Android exception 1. Window handle leakage caused by asynchronous tasks

Source: Internet
Author: User

Post exception first:

05-05 10:36:41. 4243: E/windowmanager (): Activity COM. tao. myactivity has leaked window COM. android. internal. policy. impl. phonewindow $ decorview @ 405241b0 that was originally added here05-05 10:36:41. 4243: E/windowmanager (): Android. view. windowleaked: Activity COM. tao. myactivity has leaked window COM. android. internal. policy. impl. phonewindow $ decorview @ 405241b0 that was originally added here05-05 10: 36: 41.009: E/windowmanager (4243): At android. view. viewroot. <init> (viewroot. java: 265) 10:36:41 05-05. 4243: E/windowmanager (): At android. view. windowmanagerimpl. addview (windowmanagerimpl. java: 148) 10:36:41 05-05. 4243: E/windowmanager (): At android. view. windowmanagerimpl. addview (windowmanagerimpl. java: 91) 05-05 10:36:41. 4243: E/windowmanager (): At android. view. window $ localwindowmanager. addview (Window. java: 424) 10:36:41 05-05. 4243: E/windowmanager (): At android. app. dialog. show (dialog. java: 241) 10:36:41 05-05. 4243: E/windowmanager (): At android. app. progressdialog. show (progressdialog. java: 107) 10:36:41 05-05. 4243: E/windowmanager (): At android. app. progressdialog. show (progressdialog. java: 95) 05-05 10:36:41. 4243: E/windowmanager (): At COM. unifable. activity. mysecretaryactivity. oncrea Te (mysecretaryactivity. java: 50) 10:36:41 05-05. 4243: E/windowmanager (): At android. app. instrumentation. callactivityoncreate (instrumentation. java: 1047) 10:36:41 05-05. 4243: E/windowmanager (): At android. app. activitythread. extends mlaunchactivity (activitythread. java: 1611) 10:36:41 05-05. 4243: E/windowmanager (): At android. app. activitythread. handlelaunchactivity (activitythread. java: 1663) 05-05 10: 36: 41.009: E/windowmanager (4243): At android. app. activitythread. access $1500 (activitythread. java: 117) 10:36:41 05-05. 4243: E/windowmanager (): At android. app. activitythread $ H. handlemessage (activitythread. java: 931) 10:36:41 05-05. 4243: E/windowmanager (): At android. OS. handler. dispatchmessage (handler. java: 99) 05-05 10:36:41. 4243: E/windowmanager (): At android. OS. logoff. loop (logoff. java: 130) 05-05 10:36:41. 4243: E/windowmanager (): At android. app. activitythread. main (activitythread. java: 3683) 10:36:41 05-05. 4243: E/windowmanager (): At java. lang. reflect. method. invokenative (native method) 05-05 10:36:41. 4243: E/windowmanager (): At java. lang. reflect. method. invoke (method. java: 507) 10:36:41 05-05. 4243: E/windowmanager (): At COM. android. internal. OS. zygoteinit $ methodandargscaller. run (zygot Einit. java: 906) 10:36:41 05-05. 4243: E/windowmanager (): At COM. android. internal. OS. zygoteinit. main (zygoteinit. java: 664) 10:36:41 05-05. 009: E/Windows Manager (4243): At Dalvik. system. nativestart. main (native method) is a problem encountered when creating a project: in the activity of the first interface, in order to avoid the bad user experience caused by the false death of the program, the asynchronous task asynctask is used to access the network, interact with the server, and the progressdialog control is used to inform the user of the current program progress. I checked others' information online. Finally, I understood the reason. The preceding exception indicates that a phonewindow cannot be destroyed in time due to a window handle leakage. why is there such a situation, because a serious error has occurred in the asynchronous task, and the activity is forced to close. Activity is forced to close, but progressdialog does not dismiss (), so a window handle leakage occurs. What's more serious is that this exception will overwrite the real exception we encountered in asynctask, which will often mislead us and focus too much on finding the so-called memory leakage, instead of looking for errors in asynctask. Refer to other people's solutions: this solution does not really solve the problem, but to some extent, it can expose the exception information that actually leads to the error. That is, override the ondestory () method of the activity, and call dismiss () in this method to release the reference to progressdialog.

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.