Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Picker inside SlideMenuView crashes with WindowManagerBadTokenException when touched #82

Open
thearaks opened this issue Jun 19, 2018 · 5 comments

Comments

@thearaks
Copy link

On Android, when touching a Picker inside SlideMenuView, the Dialog crashes with WindowManagerBadTokenException.

Here the stack trace:

[MonoDroid] Android.Views.WindowManagerBadTokenException: Unable to add window -- token null is not valid; is your activity running?
[MonoDroid]   at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in <d4a98e22dd594c16aa2b2444769b8e26>:0 
[MonoDroid]   at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002a] in <d4a98e22dd594c16aa2b2444769b8e26>:0 
[MonoDroid]   at Android.App.Dialog.Show () [0x0000a] in <6fb9e29d5d9c406081b6b60ff686e897>:0 
[MonoDroid]   at Xamarin.Forms.Platform.Android.AppCompat.PickerRenderer.OnClick () [0x000ec] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\PickerRenderer.cs:134 
[MonoDroid]   at Xamarin.Forms.Platform.Android.AppCompat.PickerRenderer+PickerListener.OnClick (Android.Views.View v) [0x0000b] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\PickerRenderer.cs:175 
[MonoDroid]   at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v) [0x00011] in <6fb9e29d5d9c406081b6b60ff686e897>:0 
[MonoDroid]   at (wrapper dynamic-method) System.Object.79bb8dcd-2e68-45e2-b211-d6e66f078180(intptr,intptr,intptr)
[MonoDroid]   --- End of managed Android.Views.WindowManagerBadTokenException stack trace ---
[MonoDroid] android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
[MonoDroid] 	at android.view.ViewRootImpl.setView(ViewRootImpl.java:765)
[MonoDroid] 	at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:356)
[MonoDroid] 	at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
[MonoDroid] 	at android.app.Dialog.show(Dialog.java:330)
[MonoDroid] 	at md58432a647068b097f9637064b8985a5e0.PickerRenderer_PickerListener.n_onClick(Native Method)
[MonoDroid] 	at md58432a647068b097f9637064b8985a5e0.PickerRenderer_PickerListener.onClick(PickerRenderer_PickerListener.java:30)
[MonoDroid] 	at android.view.View.performClick(View.java:6294)
[MonoDroid] 	at android.view.View$PerformClick.run(View.java:24770)
[MonoDroid] 	at android.os.Handler.handleCallback(Handler.java:790)
[MonoDroid] 	at android.os.Handler.dispatchMessage(Handler.java:99)
[MonoDroid] 	at android.os.Looper.loop(Looper.java:164)
[MonoDroid] 	at android.app.ActivityThread.main(ActivityThread.java:6494)
[MonoDroid] 	at java.lang.reflect.Method.invoke(Native Method)
[MonoDroid] 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
[MonoDroid] 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Could it be related to the fact that I'm using Xamarin.Forms 3.0 while this library is still at 2.5?
Thank you!

@jessejiang0214
Copy link
Contributor

Would you please give us some demo project?

@thearaks
Copy link
Author

Hi @jessejiang0214,
Thank you for your quick reply!

I've set up a demo project:
https://github.com/thearaks/XamarinPlayground3

Just checkout master branch, run the app, open the side menu and touch the picker (it's int the fourth row of the grid); it will crash instantly.

Thank you for your support
Mattia

@jessejiang0214
Copy link
Contributor

@thearaks Thanks for your demo, I can reproduce, but I feel that it looks more the bug for Xamarin.Android, or Android's bug.
https://stackoverflow.com/questions/5796611/dialog-throwing-unable-to-add-window-token-null-is-not-for-an-application-wi

And it seems nothing I can do in this project

@thearaks
Copy link
Author

thearaks commented Jun 22, 2018

It doesn't look an Android bug to me, maybe the Dialog is created using the wrong Context instance?
Even on that StackOverflow issue there are some suggestions that hints in that direction.
Or else I hope it's just a Xamarin.Android bug that will be fixed in future releases...

@OKameric
Copy link

Until they fix the issue, the workaround is to make Datepicker renderer and set the context to Forms.Context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants