About dialog caused by Java.lang.illegalargumentexception:view=com.android.internal.policy.impl.phonewindow$decorview not Attached to Window Manager error analysis

Source: Internet
Author: User

When running the monkey test, there was a very special problem, first look at log:

1 //CRASH:com.meizu.media.painter (PID 12491)2 3 //Short Msg:java.lang.IllegalArgumentException4 5 //Long msg:java.lang.illegalargumentexception:view=com.android.internal.policy.impl.phonewindow$decorview{ 21dd6762 V.ed .... R...... D 0,0-538,105} not attached to Window manager6 7 //Build Label: * * *8 9 //Build changelist:1443062570Ten  One //Build time:1443062722000 A  - //java.lang.illegalargumentexception:view=com.android.internal.policy.impl.phonewindow$decorview{21dd6762 V . ED ..... R...... D 0,0-538,105} not attached to Window manager -  the //At android.view.WindowManagerGlobal.findViewLocked (windowmanagerglobal.java:416) -  - //At Android.view.WindowManagerGlobal.removeView (windowmanagerglobal.java:342) -  + //At Android.view.WindowManagerImpl.removeViewImmediate (windowmanagerimpl.java:116) -  + //At Android.app.Dialog.dismissDialog (dialog.java:354) A  at //At Android.app.Dialog.dismiss (dialog.java:337) -  - //At com.***.***.***. Painterdrawactivity.closeprogressdialog (painterdrawactivity.java:60) -  - //At Com.***.***.painter. painterdrawactivity.access$000 (painterdrawactivity.java:28) -  in //At Com.***.***.painter. Painterdrawactivity$1$2.run (painterdrawactivity.java:49) -  to //At Android.os.Handler.handleCallback (handler.java:815) +  - //At Android.os.Handler.dispatchMessage (handler.java:104) the  * //At Android.os.Looper.loop (looper.java:194) $ Panax Notoginseng //At Android.app.ActivityThread.main (activitythread.java:5741) -  the //At Java.lang.reflect.Method.invoke (Native Method) +  A //At Java.lang.reflect.Method.invoke (method.java:372) the  + //At Com.android.internal.os.zygoteinit$methodandargscaller.run (zygoteinit.java:980) -  $ //At Com.android.internal.os.ZygoteInit.main (zygoteinit.java:775) $  -//

From the above log can be seen is an illegal parameter exception problem.

then why does it appear Long msg:java.lang.illegalargumentexception:view=com.android.internal.policy.impl.phonewindow$decorview{ 21dd6762 V.ed .... R...... D 0,0-538,105} Not the problem with attached to window manager? How does the crash of application itself be linked to

  What about Phonewindow? 
(1). Why did the error com.android.phone have stopped running?         by viewing the information on the Internet, you can find in the original code in its androidmanifest.xml: android:shareduserid= "Android.uid.phone" That is, with the phone in a process, so in the performance of the error will be Phonewindow. (2). Why is the view not attached to Window Manager error reported?         This error means that the view we operate is not included in the management of window manager.         We know that all window creation and management is dependent on Windows Manager, so the creation of dialog is no exception. Dialog creation process by looking at the source code, you can tell that in the constructor of dialog, a Window object is created, but we know that the Window object is not for display and is really used to display the View object. Thus a Mdecor view object is constructed through the dialog Show method, and dialog is finally displayed through the WindowManager AddView () method.         by viewing the log information we can see Painterdrawactivity.closeprogressdialog (painterdrawactivity.java:60) After viewing the corresponding Closeprogressdialog code, it was found that in the 60 line code for Dialog.dismiss ();        Search on the network found that in most cases this error occurred, The activity that created the dialog was found to be the result of dismiss dialog. For example, display a Dialog on the interface, and then dismiss Dialog when the task is finished. If the activity has been killed and restarted for some reason during the dialog display, when the task is finished, Dismiss dialog WindowManager Check, you will find that the activity of the dialog is no longer present ( Reboot once, is a new Activity), so will be reported illegalargumenTexception:view not attached to window manager. From the above analysis we can know that when dialog executes the dismiss method, it discovers that the activity that started it is gone and killed (now this is a reboot ), so the error occurs unexpectedly. (3). Why is the activity "killed"?

Because it was the log of the monkey test, it was difficult to reproduce it, only to look at the people who had similar problems on the Internet.

For the Onsaveinstancestate method, there is a description in the Android SDK: Android calls Onsaveinstancestate () before the activity becomes Vulnerable to being destroyed by the system, but does not bother calling it was when the instance was actually being destroyed By a user action (such as pressing the back key) it is said that when an activity becomes "easy" to be destroyed by the system, the activity's onsaveinstancestate will be executed, Unless the activity is actively destroyed by the user, such as when the user presses the back key. Note that the easy word here, the current activity has not been destroyed, but the system felt that it might be destroyed so the method will be executed. In this method we can save various data information in the activity, if the activity is actually killed and restarted, you can use the Onrestoreinstancestate method to restore the data information we saved before restarting the activity. The invocation of the Onsaveinstancestate method follows an important principle that when the system destroys your activity "without your permission", Onsaveinstancestate is called by the system, which is the responsibility of the system, Because it has to provide an opportunity for you to keep your data (of course, if you don't save it, you can't get it back).         so through the above analysis we can see that the activity was actually killed and started again. (4). Did dialog exist when Sactivity was killed?         Maybe everyone will have doubts, Dialog did not see, there was a mistake, how can we be sure that the dialog was definitely displayed?         When the activity is destroyed, the dialog it is attached to exists. (5). How to solve this problem?         After the above analysis we know the cause of the problem, so how to solve it? Can be resolved by the following two aspects: 1. Using ActivitY-Band Dialog control method         in the activity you need to use a dialog box, you can use the activity's own callback, such as Oncreatedialog (), ShowDialog (), Dimissdialog (), Removedialog () and so on. After all, these are the activity of the method, so it is more convenient to use, do not show the creation and manipulation of dialog objects, everything is controlled by the framework, relatively safe. 2. Limit the life cycle of the dialog         The lifetime of the created dialog object is consistent with the activity's life cycle, meaning that the dialog life cycle is limited to the oncreate of the activity ( ) and the OnDestroy () method.

About dialog caused by Java.lang.illegalargumentexception:view=com.android.internal.policy.impl.phonewindow$decorview not Attached to Window Manager error analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.