Android exception 1. Window handle leakage caused by asynchronous tasks

Source: Internet
Author: User

Post exception first:
[Java]
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 here
05-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 here
05-05 10:36:41. 009: E/WindowManager (4243): at android. view. ViewRoot. <init> (ViewRoot. java: 265)
05-05 10:36:41. 009: E/WindowManager (4243): at android. view. WindowManagerImpl. addView (WindowManagerImpl. java: 148)
05-05 10:36:41. 009: E/WindowManager (4243): at android. view. WindowManagerImpl. addView (WindowManagerImpl. java: 91)
05-05 10:36:41. 009: E/WindowManager (4243): at android. view. Window $ LocalWindowManager. addView (Window. java: 424)
05-05 10:36:41. 009: E/WindowManager (4243): at android. app. Dialog. show (Dialog. java: 241)
05-05 10:36:41. 009: E/WindowManager (4243): at android. app. ProgressDialog. show (ProgressDialog. java: 107)
05-05 10:36:41. 009: E/WindowManager (4243): at android. app. ProgressDialog. show (ProgressDialog. java: 95)
05-05 10:36:41. 009: E/WindowManager (4243): at com. uniable. activity. MySecretaryActivity. onCreate (MySecretaryActivity. java: 50)
05-05 10:36:41. 009: E/WindowManager (4243): at android. app. Instrumentation. callActivityOnCreate (Instrumentation. java: 1047)
05-05 10:36:41. 009: E/WindowManager (4243): at android. app. ActivityThread. receivmlaunchactivity (ActivityThread. java: 1611)
05-05 10:36:41. 009: E/WindowManager (4243): 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)
05-05 10:36:41. 009: E/WindowManager (4243): at android. app. ActivityThread $ H. handleMessage (ActivityThread. java: 931)
05-05 10:36:41. 009: E/WindowManager (4243): at android. OS. Handler. dispatchMessage (Handler. java: 99)
05-05 10:36:41. 009: E/WindowManager (4243): at android. OS. low.loop (low.java: 130)
05-05 10:36:41. 009: E/WindowManager (4243): at android. app. ActivityThread. main (ActivityThread. java: 3683)
05-05 10:36:41. 009: E/WindowManager (4243): at java. lang. reflect. Method. invokeNative (Native Method)
05-05 10:36:41. 009: E/WindowManager (4243): at java. lang. reflect. Method. invoke (Method. java: 507)
05-05 10:36:41. 009: E/WindowManager (4243): at com. android. internal. OS. ZygoteInit $ MethodAndArgsCaller. run (ZygoteInit. java: 906)
05-05 10:36:41. 009: E/WindowManager (4243): at com. android. internal. OS. ZygoteInit. main (ZygoteInit. java: 664)
05-05 10:36:41. 009: E/WindowManager (4243): at dalvik. system. NativeStart. main (Native Method)
 
This is a problem encountered when creating a project. In the Activity on the first interface, in order to avoid the poor user experience caused by the false death of the program, the asynchronous task <span style = "font-family: Arial, 'liberation Sans 'is used ', 'dejavu Sans ', sans-serif; border-collapse: collapse; line-height: 18px; "> AsyncTask </span> to access the network and interact with the server, and <p> <span style = "white-space: pre"> </span> <span style = "font-family: Arial, 'libation Sans ', the 'dejavu Sans ', sans-serif; border-collapse: collapse; line-height: 18px; "> ProgressDialog control informs the user of the current program progress. </Span> </p> <span style = "font-family: Arial, 'liberation Sans ', 'dejavu Sans', sans-serif; border-collapse: collapse; line-height: 18px; "> I checked others' information online to find out why.
</Span> </p> <span style = "font-family: Arial, 'liberation Sans ', 'dejavu Sans', sans-serif; border-collapse: collapse; line-height: 18px; "> the above exception means </span> <span style =" font-family: Arial, 'libation Sans ', 'dejavu Sans ', sans-serif; ">:</span> A PhoneWindow cannot be destroyed in time because the window handle is exposed. </P> <p> why is this happening? Because a serious error has occurred in an asynchronous task, and the Activity is forcibly disabled. Activity is forcibly disabled, but <span style = "font-family: Arial, 'libation Sans ', 'destu Sans', sans-serif; border-collapse: collapse; line-height: 18px; "> ProgressDialog </span> is not dimiss (), so a </p> <p> window handle leakage occurs. More seriously, this exception will overwrite the <span style = "font-family: Arial, 'liberation Sans ', 'dejavu Sans', sans-serif; border-collapse: collapse; line-height: 18px; "> real exceptions in AsyncTask are often misleading. </span>, instead of looking for <span style = "font-family: Arial, 'liberation Sans ', 'dejavu Sans', and sans-serif; border-collapse: collapse; line-height: 18px; "> AsyncTask </span>
</P> <p>. </P> <p>
</P> <span style = "white-space: pre"> </span> refer to others' solutions: </p> <span style = "white-space: pre;"> </span> This solution cannot solve the problem, however, to some extent, the exception information that truly leads to errors can be exposed. That is, override the onDestroy method of the Activity, and call dismiss in the method to cancel the <span style = "font-family: Arial, 'liberation Sans ', 'dejavu Sans', sans-serif; border-collapse: collapse; line-height: 18px; "> ProgressDialog and so on. </Span> </p>



From LonelyRoamer's column

Related Article

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.