OnDismissListener获取旧值

时间:2015-04-11 17:57:41

标签: android

首先,代码:

public class MyApp extends ActionBarActivity {
    protected static boolean Stopped;
    protected static AlertDialog alertDialog;
    protected static Activity activity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Stopped = false;
        activity = this;
        super.onCreate(savedInstanceState);
        //...
    }

    @Override
    protected void onStop() {
        Stopped = true;
        super.onStop();
        if(alertDialog != null)
            alertDialog.dismiss();
    }
}

稍后在我的代码中:

AlertDialog.Builder builder = new AlertDialog.Builder(MyApp.activity);
builder.setTitle("Title");
builder.setMessage("Message");
final AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(true);
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
    @Override
    public void onDismiss(DialogInterface dialog) {
        if (!MyApp.Stopped)
            MyApp.alertDialog = null;
    }
});
dialog.show();
MyApp.alertDialog = dialog;

问题是:调用onStop()时,Stopped 为真,但在此之后,在onDismiss()中,MyApp.Stopped仍然是的

有没有办法纠正这个?

onStop()

之前调用P.S。:onDismiss()

0 个答案:

没有答案