Crash on Orientation change when Dialog and Popup window are both visible

thedesolatesoul

Expert
Licensed User
Longtime User
I was doing some tests for changing orientations. I use corwin42's AHQuickActions library for a menu which uses the PopupWindow class.

If I have a custom dialog open and change orientation, it works okay.
If I have a Popup menu open and change orientation, it works okay.

When I have launched a dialog from the popup menu, both of them are visible and then I get a crash here on orientation change:


B4X:
java.lang.IllegalArgumentException: View not attached to window manager
   at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:653)
   at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:362)
   at android.view.WindowManagerImpl$CompatModeWrapper.removeViewImmediate(WindowManagerImpl.java:170)
   at android.widget.PopupWindow.dismiss(PopupWindow.java:1256)
   at de.amberhome.quickaction.PopupWindows.dismiss(PopupWindows.java:141)
   at com.maximus.quickpopup.quickpopup$3.onClick(quickpopup.java:169)
   at android.view.View.performClick(View.java:4084)
   at android.view.View$PerformClick.run(View.java:16966)
   at android.os.Handler.handleCallback(Handler.java:615)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4931)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
   at dalvik.system.NativeStart.main(Native Method)

I think due to the dialog the onClick handler for the popup has not finished yet. When it gets dismissed, the Activity is killed, and this code is run afterwards.

I think there are two solutions:
- Use CallSubDelayed to call the sub that shows the dialog. This lets the onClick handler to finish.
- Change the onClick handler to dismiss the popup before delegating the event. Not sure what other effects that will have
 

corwin42

Expert
Licensed User
Longtime User
Since the object even has an onDismiss event I won't change the order in the library.

Perhaps another solution would be to remember the click event in a global variable and show the dialog in the dismiss event. But I think the CallSubDelayed solution would be much cleaner.
 
Upvote 0
Top