2014-03-18 29 views
1

嘿,我正在做一個簡單的web視圖的android應用程序。我想在某些URL上將用戶重定向到瀏覽器。我想以對話框的形式顯示一條消息,提醒用戶他們正在被重定向到他們的瀏覽器。用戶將點擊確定,然後用戶被重定向。如何在顯示對話框時暫停安卓應用程序?

下面的代碼是我的。問題是應用程序繼續進行重定向而不等待用戶單擊對話框上的確定。我想暫停並繼續任何活動,只有當用戶點擊確定。

  DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { /*DialogInterface called while setting the AlertDialog Buttons */ 


       public void onClick(DialogInterface dialog, int which) { 

        //Here you can perform functions of Alert Dialog Buttons as shown 
        switch (which){ 
         case DialogInterface.BUTTON_POSITIVE: 

          //I want the app to pause here. 
          //MainActivity.this.onPause(); does not work 
          break; 
        } 
       } 
      }; 

      AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); 
      builder.setTitle("Title");// Set the Title of Alert Dialog 
      builder.setMessage("We are taking you to the admin page.").setPositiveButton("OK",dialogClickListener).show(); 

謝謝,我不想用一個wait(),因爲我希望我的用戶承認正在發生的事情通過點擊按鈕

回答

0

試試這個:

public class MyClass extends Activity { 

    private boolean mustScan = true; 

    protected void onCreate(Bundle b) { 
     if (mustScan) { 
      // Just scan 
      // Note: If you use a Thread with a while loop, use this: 
      // while (true) {if (mustScan) {} } 
     } 
    } 

    // This is the method you use to show the Dialog 
    private void showResults (SomeResults here) { 
     // Show the dialog 
     // ... 
     mustScan = false; 
     // Also, in the OnClickListener of the buttons add "mustScan = true;" 
    } 
相關問題