Delay before redirect page

There is a link that redirects 5 seconds to another page, how can I make a delay before redirecting Here is an example link: http://s.spynetstation.com/m/Logistics/Logistics%20-%20Medical%20History%20NHSDL09,%202007/ 05% 20Logistics% 20-% 20Safe% 20On% 20My% 20Side.mp3 Code

public void ShowTrack(String smetaout,String stitleout){
    AlertDialog.Builder alert = new AlertDialog.Builder(this); 
    alert.setTitle(stitleout);

    WebView wv = new WebView(this);

    wv.setWebViewClient(new WebViewClient() {

        @Override
           public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) {
             Log.d("My Webview", "shouldOverrideUrlLoading"+urlNewString);
               if (!loadingFinished) {
                  redirect = true;
               }

           loadingFinished = false;
           view.loadUrl(urlNewString);
           Log.d("My Webview", urlNewString);
           return false;
           }

           public void onPageStarted(WebView view, String url) {
               Log.d("My Webview", "onPageStarted"+url);
                loadingFinished = false;

            }

           @Override
           public void onPageFinished(WebView view, String url) {
               if(!redirect){
                  loadingFinished = true;
               }

               if(loadingFinished && !redirect){

               } else{
                  redirect = false; 
               }
               Log.d("My Webview", "onPageFinished"+url);
            }

    });
    wv.loadUrl(smetaout);
    alert.setView(wv);
    alert.setNegativeButton("Close", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    });
    alert.show();
}

      

+3


source to share


2 answers


Insert any delay (Timer, Asynchronous, etc.) before .loadUrl

. For example:



new CountDownTimer( 5000, 5000)
 {
   public void onTick( long millisUntilFinished) {}
   public void onFinish()
    {
      view.loadUrl(urlNewString);
    }
 }.start();                  

      

+1


source


Try the following:

public void ShowTrack(String smetaout,String stitleout){
    AlertDialog.Builder alert = new AlertDialog.Builder(this); 
    alert.setTitle(stitleout);

    WebView wv = new WebView(this);

    // Progress dialog starts
    ProgressDialog progressDialog = ProgressDialog.show(YourActivity.this, "", "Loading... ",true ,true);

    wv.setWebViewClient(new WebViewClient() {

       @Override
       public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) {
           Log.d("My Webview", "shouldOverrideUrlLoading"+urlNewString);
           if (!loadingFinished) {
               redirect = true;
           }

           loadingFinished = false;
           view.loadUrl(urlNewString);
           Log.d("My Webview", urlNewString);
           return false;
       }

       public void onPageStarted(WebView view, String url) {
           Log.d("My Webview", "onPageStarted"+url);
           loadingFinished = false;

       }

       @Override
       public void onPageFinished(WebView view, String url) {

           final Handler handler = new Handler();
           handler.postDelayed(new Runnable() {
               @Override
               public void run() {
                   // Do something after 5s = 5000ms
                   progressDialog.dismiss();
               }
           }, 5000);

           if(!redirect){
              loadingFinished = true;
           }

           if(loadingFinished && !redirect){

           } else{
              redirect = false; 
           }
           Log.d("My Webview", "onPageFinished"+url);
       }

    });
    wv.loadUrl(smetaout);
    alert.setView(wv);
    alert.setNegativeButton("Close", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    });
    alert.show();
}

      



Hope this is what you want.

+1


source







All Articles