2014-03-18 35 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;" 
    } 
相关问题