Android exception: view not attached to Window Manager

Source: Internet
Author: User

 

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

 

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.