如何知道某项活动已被撤回?

时间:2015-05-04 13:18:41

标签: android

activity内,有一个按钮,点击后会显示AlertDialog。解除此对话框后,如果用户单击对话框的BUTTON_NEGATIVE,我想执行一些任务。那么如何识别活动是reshown?我知道活动life-cycle,我实现了已知的生命周期状态,但他们没有开始我想要执行的任务!

我实现onDismissListener但它崩溃了:

private OnDismissListener dismissListener = new OnDismissListener() {

    @Override
    public void onDismiss(DialogInterface dialog) {

        if (dialog instanceof ConfirmChoixDownloadDialogView) {

            if (btnClicked == OUI) {

                ...

            }

            else if (btnClicked == NON) { // the BUTTON_NEGATIVE


                Intent i = new Intent(activity, SelectionQuartierActivity.class); // activity is the activity containing the button which shows the Dialog
                activity.startActivity(i);

            }

        }

    }

};

2 个答案:

答案 0 :(得分:0)

将OnDismissListener添加到对话框:

AlertDialog a = new AlertDialog();
a.setOnDismissListener(new DialogInterface.OnDismissListener()
{
    @Override
    public void onDismiss(DialogInterface dialog)
    {

    }
});

答案 1 :(得分:0)

好的,我通过实施activity的{​​{1}}方法并设置activity,从Dialog开始onWindowFocusChanged的提示activity的{​​{1}}内public static的{​​{1}}变量!