Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: WindowLeaked when rotate screen and dialog open
    primarykey
    data
    text
    <p>I have a dialog that is brought up when you click on an image in my activity. When the dialog is open and the user rotates the screen, the following is shown in my LogCat:</p> <pre><code>08-23 09:47:47.151: E/WindowManager(15589): Activity my.activity.MyActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43554748 that was originally added here 08-23 09:47:47.151: E/WindowManager(15589): android.view.WindowLeaked: Activity my.activity.MyActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43554748 that was originally added here 08-23 09:47:47.151: E/WindowManager(15589): at android.view.ViewRoot.&lt;init&gt;(ViewRoot.java:247) 08-23 09:47:47.151: E/WindowManager(15589): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148) 08-23 09:47:47.151: E/WindowManager(15589): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) 08-23 09:47:47.151: E/WindowManager(15589): at android.view.Window$LocalWindowManager.addView(Window.java:424) 08-23 09:47:47.151: E/WindowManager(15589): at android.app.Dialog.show(Dialog.java:241) 08-23 09:47:47.151: E/WindowManager(15589): at tip.machine.MyActivity$8.onClick(MyActivity.java:385) 08-23 09:47:47.151: E/WindowManager(15589): at android.view.View.performClick(View.java:2408) 08-23 09:47:47.151: E/WindowManager(15589): at android.view.View$PerformClick.run(View.java:8816) 08-23 09:47:47.151: E/WindowManager(15589): at android.os.Handler.handleCallback(Handler.java:587) 08-23 09:47:47.151: E/WindowManager(15589): at android.os.Handler.dispatchMessage(Handler.java:92) 08-23 09:47:47.151: E/WindowManager(15589): at android.os.Looper.loop(Looper.java:123) 08-23 09:47:47.151: E/WindowManager(15589): at android.app.ActivityThread.main(ActivityThread.java:4627) 08-23 09:47:47.151: E/WindowManager(15589): at java.lang.reflect.Method.invokeNative(Native Method) 08-23 09:47:47.151: E/WindowManager(15589): at java.lang.reflect.Method.invoke(Method.java:521) 08-23 09:47:47.151: E/WindowManager(15589): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858) 08-23 09:47:47.151: E/WindowManager(15589): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 08-23 09:47:47.151: E/WindowManager(15589): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>What I did was declare the dialog globally by writing <code>Dialog dialog</code>, and in my <code>onPause</code>, I wrote this:</p> <pre><code>@Override protected void onPause() { System.out.println("IN PAUSE!"); try { dialog.dismiss(); System.out.println("IN TRY!"); } catch (java.lang.NullPointerException exception) {System.out.println("IN CATCH!");} super.onPause(); } </code></pre> <p>The catch block, I thought, would catch the error if <code>dialog</code> was not instantiated. Anyways, every time I rotate, whether or not the dialog is open, I enter the catch block only. When the dialog is open and I rotate, I get the same stack trace as above (it goes straight to the catch block). So it never even seems to attempt the <code>dialog.dismiss()</code> which is why I still get the <code>WindowLeaked</code> message.</p> <p>Any ideas? Must be something wrong with my variable declaration/instantiation. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload