Ok, solved. Actually, the code that I've posted works. The problem comes when the pages that I wanted to load ask you to leave the page through a Javascript popup. You have two ways to handle this behaviour:
- Instantiate
WebChromeClient
and handle the popup - Create single WebView instances and save them inside the inner class.
So, this solution (the second one) works as well, even if more memory expensive (maybe?):
public class MainActivity extends Activity {
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] urlArr = {"http://www.google.com", "http://www.cnn.com", "http://www.wired.com"};
int delay = 30 * 1000;
Handler handler = new Handler();
for(int i = 0; i < urlArr.length; i++) {
WebView wv = new WebView(this);
wv.setWebViewClient(new WebViewClient());
wv.getSettings().setJavaScriptEnabled(true);
MyRunnable runnable = new MyRunnable(urlArr[i], wv);
handler.postDelayed(runnable, delay);
delay = delay + 30 * 1000;
}
}
private class MyRunnable implements Runnable {
private String url;
private WebView wv;
public MyRunnable(String url, WebView wv) {
this.url = url;
this.wv = wv;
}
public void run() {
setContentView(wv);
wv.loadUrl(url);
Log.d("MainActivity", "PageLoaded: " + url);
}
}
}
Hope that this helps someone, thank you anyway!