I want to load URL one by one.I used String array to store the URL.My requirement is that if the webview loads the first url it should print the msg \"page started\" when p
Try coding out the WebViewClient extension to notify your Activity when the loading is complete. I've attempted to modify your code to do just that:
package com.browser;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class Browser extends Activity {
private MyWebView mwv = null;
private MyWeb myweb = null;
private List urls = null;
private String[] url = new String[] {"http://www.yahoo.com","http://www.google.com","http://www.ibnlive.com"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mwv = new MyWebView(this);
myweb = new MyWeb(this);
mwv.setWebViewClient(myweb);
urls = Arrays.asList(url);
loadNextUrl(null);
}
private loadNextUrl(String fromUrl) {
if (fromUrl == null) {
myweb.setOriginalUrl(urls.get(0));
mwv.loadUrl(urls.get(0));
} else {
if (urls.indexOf(fromUrl) == urls.size() - 1) return;
String newUrl = urls.get(urls.indexOf(fromUrl) + 1);
myweb.setOriginalUrl(newUrl);
mwv.loadUrl(newUrl);
}
}
public class MyWebView extends WebView{
public MyWebView(Context context) {
super(context);
}
}
public class MyWeb extends WebViewClient{
Browser activity = null;
// Prevent redirects from messing with URL array
String originalUrl = null;
public MyWeb(Browser activity) {
this.activity = activity;
}
public setOriginalUrl(String url) {
this.originalUrl = url;
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
System.out.println("LOADING");
return false;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
System.out.println("PageStarted: " + url);
}
@Override
public void onPageFinished(WebView view, String url){
System.out.println("PageFinished: " + url);
activity.loadNextUrl(originalUrl);
}
}
}