开发者

IllegalArgumentException? Why?

Can anyone explain to me why this error occures, or even better how do I handle it? I can not reproduce it. It is one of those errors that happends once out of a 1000.

Background: The user is trying to log in, a progress dialog is showing, a http request is sent in async task, the progress dialog is dissmissed. Error occures, app FC.

LoginActivity.java

 255:   private void dismissProgress() {  
 256:     if (mProgress != null) {  
 257:         mProgress.dismiss();  
 258:         mProgress = null;  
 259:     }  
 260:   }  

java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:391)
at android.view.WindowManagerImpl.removeView(WindowManagerImp开发者_JAVA百科l.java:236)
at android.view.Window$LocalWindowManager.removeView(Window.java:432)
at android.app.Dialog.dismissDialog(Dialog.java:278)
at android.app.Dialog.access$000(Dialog.java:71)
at android.app.Dialog$1.run(Dialog.java:111)
at android.app.Dialog.dismiss(Dialog.java:268)
at se.magpern.LoginActivity.dismissProgress(LoginActivity.java:257)
at se.magpern.LoginActivity.access$5(LoginActivity.java:255)
at se.magpern.LoginActivity$DoTheLogin.onPostExecute(LoginActivity.java:293)
at se.magpern.LoginActivity$DoTheLogin.onPostExecute(LoginActivity.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:417)
at android.os.AsyncTask.access$300(AsyncTask.java:127)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:4937)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)


This can happen if the user either dismisses the view (e.g. a dialog that can be backed out of) or if the user switches to a different activity while your task is running. You should seriously think about using Android's activity-native dialog showing/dismissing instead of trying to keep a reference to the views yourself. But if you are handling it yourself, you may want to check if the dialog is actually showing using the dialog's isShowing() method before trying to dismiss it.


I've seen this happen when a latent update comes in for a progress dialog that has already been fully or partially dismissed. Either the user is requesting a dismissal at the same time the os is trying to dismiss the view and its already been disconnected from the window or vice versa.

There is a race condition between the code that dismisses the progress window when a button is clicked and the code that dismisses the progress window in another fashion. The mostly likely place to look for this race condition is where your requests for dismissing the windows are put onto the view thread (button handler or a code callback).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜