Android活动在退出前提示

时间:2012-01-12 19:50:32

标签: android

我试图在退出活动之前提示用户,具体取决于响应,将值传回给调用活动,目前这就是我正在做的事情。

private void quit() {
AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
        alt_bld.setMessage("Have you finished ?")
                .setCancelable(false)
                .setPositiveButton("Yes",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {
                                exit(2);

                            }
                        })
                .setNegativeButton("No",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {
                                exit(0);
                            }
                        });
        alert = alt_bld.create();
        // Title for AlertDialog
        alert.setTitle(showString);
        // Icon for AlertDialog
        alert.setIcon(R.drawable.icon);
        alert.show();
}
private void exit(int flag) {
    if (flag == 1) {
        setResult(Consts.QUITREMOTE);
    } else if (flag == 2) {
        Intent i = new Intent();
        i.putExtra("showID", ID);
        setResult(Consts.REMOVESHOW, i);
    }
    alert.dismiss();
    this.finish();
}

但是这引发了一次激动,因为警报对话框没有完成:

01-12 14:48:12.744: E/WindowManager(1081): Activity x has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@405ff580 that was originally added here

我该怎么做?

1 个答案:

答案 0 :(得分:0)

我弄清楚问题是什么,我也叫退出(假);来自onDestroy。如果删除了quit(false),上面的代码可以正常工作