在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);
}
}
}
};
答案 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}}变量!