The monkey test was used before the company's project was launched recently. This error always occurred: exception: view not attached to window manager. This error occurs when the dismiss method of dialog is called when the activity disappears. My solution is:
Judge the current activity. isfinishing () +! = NULL + isshowing (). These three methods prevent this problem.
Exception: view not attached to Window Manager/processdialog call is an exception thrown during screen rotation 01-28 14:09:07. 889: Error/androidruntime (5084): Java. lang. illegalargumentexception: view not attached to Window Manager
01-28 14:09:07. 889: Error/androidruntime (5084): at Android. View. windowmanagerimpl. findviewlocked (windowmanagerimpl. Java: 355)
01-28 14:09:07. 889: Error/androidruntime (5084): at Android. View. windowmanagerimpl. removeview (windowmanagerimpl. Java: 200)
01-28 14:09:07. 889: Error/androidruntime (5084): at Android. View. Window $ localwindowmanager. removeview (window. Java: 432)
01-28 14:09:07. 889: Error/androidruntime (5084): at Android. App. Dialog. dismissdialog (dialog. Java: 278)
During the dialog circled process, if the screen direction of the mobile phone changes, this exception may be thrown because the view is re-painted after the screen is flipped, And the dialog is executing dismiss () when,
The original location cannot be found. To solve this problem, the simplest method is:
1. Restrict screen flip
Android: screenorientation = "Portrait" can be set in androidmanifest. xml"
2. If the view needs to be flipped, restrict the view to be repainted.
Android: configchanges = "orientation | keyboardhidden | navigation" can be set in androidmanifest. xml"
3. If you have to flip and re-draw the view, you can use the code to control it.
Private void lockscreen (){
Configuration newconfig = getresources (). getconfiguration ();
If (newconfig. Orientation = configuration. orientation_landscape) {// landscape
U. dout ("orientation_landscape lock it! ");
Setrequestedorientation (activityinfo. screen_orientation_landscape );
} Else if (newconfig. Orientation = configuration. orientation_portrait) {// landscape
U. dout ("screen_orientation_portrait lock it! ");
Setrequestedorientation (activityinfo. screen_orientation_portrait );
} Else if (newconfig. hardkeyboardhidden = configuration. keyboardhidden_no) {// the keyboard is not disabled. Horizontal screen orientation
Setrequestedorientation (activityinfo. screen_orientation_landscape );
} Else if (newconfig. hardkeyboardhidden = configuration. keyboardhidden_yes) {// disable the keyboard. The screen direction is vertical
Setrequestedorientation (activityinfo. screen_orientation_portrait );
}
}
Private void unlockscreen (){
U. dout ("unlock! ");
Setrequestedorientation (activityinfo. screen_orientation_sensor );
}
Refer:
Http://www.2cto.com/kf/201202/119310.html