简体   繁体   中英

Android Studio WebView

I have a WebView and I need to open a few Websites which are saved in a Array one after the other. This should been repeated infinity times and each Website should be stayed open for x seconds.

public class MainActivity extends AppCompatActivity {
private String[] links = {"https://www.google.at/?gws_rd=ssl", "http://stackoverflow.com/"};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    View decorView = getWindow().getDecorView();
    int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);
    WebView myWebView = (WebView) findViewById(R.id.webview);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    myWebView.setWebViewClient(new WebViewClient());
    while(true) {
        myWebView.loadUrl(links[0]);
        myWebView.loadUrl(links[1]);
    }
}

If I try to open just one link without a loop it is working. But if I try it with the loop it Shows me a blackscreen.

I think you have to try this

int position=0;
textview.setText("page started");
browser.loadUrl("your first url");
browser.setWebChromeClient(new WebChromeClient()
{
   public void onProgressChanged(WebView view, int progress) 
   {
      if(progress == 100)
      {
         textview.setText("page finished");
         if(position==0)
         {
           browser.loadUrl("your second url");
           position=1;
           textview.setText("page started");
         } 
         if(position==1)
         {
           browser.loadUrl("your third url");
           position=2;
           textview.setText("page started");
         } 
      }
   }

});

for more details refer this link How to load URL consecutively one by one

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM