我在 Activity example.activity.SetupManage 中。经过一些操作后,我调用了一个显示通知消息的对话框。但即使我不点击 OK 按钮,所有后续代码都会执行,所以当我杀死所有 Activity 时,对话框会产生问题。我能做些什么来解决我的问题?
AlertDialog myAlertDialog;
public void onDestroy(Bundle savedInstanceState){
if(myAlertDialog.isShowing())
myAlertDialog.dismiss();
}
// *** some operations *** //
try{
myAlertDialog = new AlertDialog.Builder(this)
.setTitle("Notification")
.setMessage("Operation Failed")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
})
.show();
}
catch(Exception ex){
}
try{
Intent myIntent = new Intent();
myIntent.setClassName("example.activity", "example.activity.MainActivity");
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|
Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(myIntent);
}catch(Exception ex){
}
错误信息:
10-16 15:33:11.120: E/WindowManager(4360): Activity example.activity.SetupManage has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@415ca638 that was originally added here
10-16 15:33:11.120: E/WindowManager(4360): at example.activity.SetupManage.CleanDatabase(SetupManage.java:61)
10-16 15:33:11.120: E/WindowManager(4360): at android.view.ViewRoot.<init>(ViewRoot.java:288)
10-16 15:33:11.120: E/WindowManager(4360): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:249)
10-16 15:33:11.120: E/WindowManager(4360): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:193)
10-16 15:33:11.120: E/WindowManager(4360): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:118)
10-16 15:33:11.120: E/WindowManager(4360): at android.view.Window$LocalWindowManager.addView(Window.java:532)
10-16 15:33:11.120: E/WindowManager(4360): at android.app.Dialog.show(Dialog.java:269)
10-16 15:33:11.120: E/WindowManager(4360): at android.app.AlertDialog$Builder.show(AlertDialog.java:907)
10-16 15:33:11.120: E/WindowManager(4360): at example.activity.SetupManage.CleanDatabase(SetupManage.java:61)