這是問題,我有一個對話框,只有在用戶第一次安裝我的應用程序時出現。在使用我自己的設備進行測試後,我發現在彈出框之後無所作爲會導致應用程序崩潰。我的目的是讓這個對話框成爲用戶在安裝應用程序後看到的第一件事。它確實出現,但是如果用戶在大約3秒內沒有按下按鈕,則會導致應用程序崩潰。但是,如果我在崩潰後重新啓動應用程序,那麼該框將永久顯示,直到用戶按下一個按鈕,這是我打算使用該框的目標。對話框導致應用程序崩潰
這裏是logcat的:
12-13 15:25:28.625: ERROR/WindowManager(15315): Activity com.nick.simplequiz.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41506ff0 V.E..... R....... 0,0-684,679} that was originally added here
android.view.WindowLeaked: Activity com.nick.simplequiz.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41506ff0 V.E..... R....... 0,0-684,679} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:458)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:94)
at android.app.Dialog.show(Dialog.java:286)
at com.nick.simplequiz.MainActivity.onCreate(MainActivity.java:216)
at android.app.Activity.performCreate(Activity.java:5165)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1103)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2419)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520)
at android.app.ActivityThread.access$600(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1366)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:5751)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:115)
at dalvik.system.NativeStart.main(Native Method)
,這是根據logcat的在錯誤發生的行:
alertDialog.show();
什麼可能會造成這種情況發生?
這是代碼,該onCreate
方法內:
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
alertDialogBuilder.setCancelable(false);
alertDialogBuilder.setTitle("...."); //Set the title of the box
alertDialogBuilder.setMessage("....");
alertDialogBuilder.setPositiveButton("Dismiss", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel(); //when they click dismiss we will dismiss the box
SharedPreferences.Editor edit2 = sp.edit();
edit2.putInt("SHOW", 1);
edit2.commit();
}
});
alertDialogBuilder.setNegativeButton("", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
.......
}
});
AlertDialog alertDialog = alertDialogBuilder.create(); //create the box
alertDialog.show(); //*************error happens here
當你說什麼都不做時,設備進入睡眠/恢復時崩潰了嗎?這裏是否有某種時間組件? – thegrinner
發佈代碼,其中是alertDialog.show(); – ramaral
在應用程序打開後等待3秒後崩潰 – ez4nick