我正在覆蓋後退按鈕。我想在離開我的應用程序時向用戶顯示確認對話框。在創建對話框我得到了以下錯誤無法創建提示對話框
Activity com.example.netlogger.ActivityLogin has leaked window [email protected] that was originally added here
04-16 16:47:40.885: E/WindowManager(7757): android.view.WindowLeaked: Activity com.example.netlogger.ActivityLogin has leaked window [email protected] that was originally added here
04-16 16:47:40.885: E/WindowManager(7757): at android.view.ViewRoot.<init>(ViewRoot.java:247)
04-16 16:47:40.885: E/WindowManager(7757): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
04-16 16:47:40.885: E/WindowManager(7757): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
04-16 16:47:40.885: E/WindowManager(7757): at android.view.Window$LocalWindowManager.addView(Window.java:424)
04-16 16:47:40.885: E/WindowManager(7757): at android.app.Dialog.show(Dialog.java:241)
04-16 16:47:40.885: E/WindowManager(7757): at com.example.netlogger.ActivityLogin.onBackPressed(ActivityLogin.java:130)
04-16 16:47:40.885: E/WindowManager(7757): at android.app.Activity.onKeyUp(Activity.java:1888)
04-16 16:47:40.885: E/WindowManager(7757): at android.view.KeyEvent.dispatch(KeyEvent.java:1063)
04-16 16:47:40.885: E/WindowManager(7757): at android.app.Activity.dispatchKeyEvent(Activity.java:2068)
04-16 16:47:40.885: E/WindowManager(7757): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1703)
04-16 16:47:40.885: E/WindowManager(7757): at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2473)
04-16 16:47:40.885: E/WindowManager(7757): at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2443)
04-16 16:47:40.885: E/WindowManager(7757): at android.view.ViewRoot.handleMessage(ViewRoot.java:1735)
04-16 16:47:40.885: E/WindowManager(7757): at android.os.Handler.dispatchMessage(Handler.java:99)
04-16 16:47:40.885: E/WindowManager(7757): at android.os.Looper.loop(Looper.java:123)
04-16 16:47:40.885: E/WindowManager(7757): at android.app.ActivityThread.main(ActivityThread.java:4633)
04-16 16:47:40.885: E/WindowManager(7757): at java.lang.reflect.Method.invokeNative(Native Method)
04-16 16:47:40.885: E/WindowManager(7757): at java.lang.reflect.Method.invoke(Method.java:521)
04-16 16:47:40.885: E/WindowManager(7757): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
04-16 16:47:40.885: E/WindowManager(7757): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-16 16:47:40.885: E/WindowManager(7757): at dalvik.system.NativeStart.main(Native Method)
我的代碼如下
@Override
public void onBackPressed() {
super.onBackPressed();
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(this);
if (!prefs.getBoolean("ask_for_exit", false)) {
exitAlertDialog = new Builder(ActivityLogin.this)
.setTitle("Are You Sure?")
.setMessage("Are you sure you want to exit")
.setPositiveButton("YES",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
finish();
}
})
.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
exitAlertDialog.dismiss();
}
}).create();
exitAlertDialog.show();
}
}
這是什麼錯誤意味着什麼?如果有任何線索,請告訴我。謝謝!
謝謝。你做對了 –
很高興聽到:) –