我开发了一个Android应用程序。它在4.4版本的手机中运行良好,但是当我在2.2版本的手机上运行它时会显示以下错误信息。
11-19 16:25:26.012: E/WindowManager(12231): Activity com.example.smart_survey.QR has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@406beb98 that was originally added here
11-19 16:25:26.012: E/WindowManager(12231): android.view.WindowLeaked: Activity com.example.smart_survey.QR has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@406beb98 that was originally added here
11-19 16:25:26.012: E/WindowManager(12231): at android.view.ViewRoot.<init>(ViewRoot.java:263)
11-19 16:25:26.012: E/WindowManager(12231): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:171)
11-19 16:25:26.012: E/WindowManager(12231): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:114)
11-19 16:25:26.012: E/WindowManager(12231): at android.view.Window$LocalWindowManager.addView(Window.java:424)
11-19 16:25:26.012: E/WindowManager(12231): at android.app.Dialog.show(Dialog.java:241)
11-19 16:25:26.012: E/WindowManager(12231): at com.example.smart_survey.QR$Logs.onPreExecute(QR.java:362)
11-19 16:25:26.012: E/WindowManager(12231): at android.os.AsyncTask.execute(AsyncTask.java:391)
11-19 16:25:26.012: E/WindowManager(12231): at com.example.smart_survey.QR$UpdateScore.onPostExecute(QR.java:255)
11-19 16:25:26.012: E/WindowManager(12231): at com.example.smart_survey.QR$UpdateScore.onPostExecute(QR.java:1)
11-19 16:25:26.012: E/WindowManager(12231): at android.os.AsyncTask.finish(AsyncTask.java:417)
11-19 16:25:26.012: E/WindowManager(12231): at android.os.AsyncTask.access$300(AsyncTask.java:127)
11-19 16:25:26.012: E/WindowManager(12231): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
11-19 16:25:26.012: E/WindowManager(12231): at android.os.Handler.dispatchMessage(Handler.java:99)
11-19 16:25:26.012: E/WindowManager(12231): at android.os.Looper.loop(Looper.java:130)
11-19 16:25:26.012: E/WindowManager(12231): at android.app.ActivityThread.main(ActivityThread.java:3687)
11-19 16:25:26.012: E/WindowManager(12231): at java.lang.reflect.Method.invokeNative(Native Method)
11-19 16:25:26.012: E/WindowManager(12231): at java.lang.reflect.Method.invoke(Method.java:507)
11-19 16:25:26.012: E/WindowManager(12231): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
11-19 16:25:26.012: E/WindowManager(12231): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
11-19 16:25:26.012: E/WindowManager(12231): at dalvik.system.NativeStart.main(Native Method)
11-19 16:25:26.653: E/AndroidRuntime(12231): FATAL EXCEPTION: main
11-19 16:25:26.653: E/AndroidRuntime(12231): java.lang.IllegalArgumentException: View not attached to window manager
11-19 16:25:26.653: E/AndroidRuntime(12231): at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:378)
11-19 16:25:26.653: E/AndroidRuntime(12231): at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:223)
11-19 16:25:26.653: E/AndroidRuntime(12231): at android.view.Window$LocalWindowManager.removeView(Window.java:432)
11-19 16:25:26.653: E/AndroidRuntime(12231): at android.app.Dialog.dismissDialog(Dialog.java:278)
11-19 16:25:26.653: E/AndroidRuntime(12231): at android.app.Dialog.access$000(Dialog.java:71)
11-19 16:25:26.653: E/AndroidRuntime(12231): at android.app.Dialog$1.run(Dialog.java:111)
11-19 16:25:26.653: E/AndroidRuntime(12231): at android.app.Dialog.dismiss(Dialog.java:268)
11-19 16:25:26.653: E/AndroidRuntime(12231): at com.example.smart_survey.QR$Logs.onPostExecute(QR.java:420)
11-19 16:25:26.653: E/AndroidRuntime(12231): at com.example.smart_survey.QR$Logs.onPostExecute(QR.java:1)
11-19 16:25:26.653: E/AndroidRuntime(12231): at android.os.AsyncTask.finish(AsyncTask.java:417)
11-19 16:25:26.653: E/AndroidRuntime(12231): at android.os.AsyncTask.access$300(AsyncTask.java:127)
11-19 16:25:26.653: E/AndroidRuntime(12231): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
11-19 16:25:26.653: E/AndroidRuntime(12231): at android.os.Handler.dispatchMessage(Handler.java:99)
11-19 16:25:26.653: E/AndroidRuntime(12231): at android.os.Looper.loop(Looper.java:130)
11-19 16:25:26.653: E/AndroidRuntime(12231): at android.app.ActivityThread.main(ActivityThread.java:3687)
11-19 16:25:26.653: E/AndroidRuntime(12231): at java.lang.reflect.Method.invokeNative(Native Method)
11-19 16:25:26.653: E/AndroidRuntime(12231): at java.lang.reflect.Method.invoke(Method.java:507)
11-19 16:25:26.653: E/AndroidRuntime(12231): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
11-19 16:25:26.653: E/AndroidRuntime(12231): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
11-19 16:25:26.653: E/AndroidRuntime(12231): at dalvik.system.NativeStart.main(Native Method)
有人可以帮我吗
答案 0 :(得分:2)
I think the actual problem is that, you want to show a ProgressDialog or dismiss a ProgressDialog when your activity has been destroyed.
So before showing or dismissing the dialog be sure that your activity is not destroy using this code !YourActivity.this.isDestroyed().
Try this for that:
private ProgressDialog progressDialog;
try {
progressDialog = new ProgressDialog(mContext);
if (progressDialog != null && !progressDialog.isShowing() && !YourActivity.this.isDestroyed()) {
progressDialog.setMessage("Please wait..");
progressDialog.setCancelable(false);
progressDialog.show();
}
}
catch (Exception e) {
Log.e(TAG, "error", e);
}
And when you dismiss dialog do this
if(progressDialog.isShowing()){
progressDialog.dismiss();
}
Hope this will help you
答案 1 :(得分:0)
如果您要创建Dialog
getApplicationContext()
作为其context
参数,请将其更改为YourActivity.this
。