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

Android.Views.WindowManagerBadTokenException: Exception of type 'Android.Views.WindowManagerBadTokenException' was thrown #3

Open
BrunoVT1992 opened this issue Oct 23, 2014 · 15 comments

Comments

@BrunoVT1992
Copy link

Hi,
I used your code for my app but when I invoke an action in my android page renderer I get the above error. This is my code:

protected override void OnElementChanged(ElementChangedEventArgs e)
{
base.OnElementChanged(e);

        var activity = this.Context as Activity;

        var auth = new OAuth2Authenticator(
            clientId: App.GoogleApiClientId,
            clientSecret: App.GoogleApiClientSecret,
            scope: "email",
            authorizeUrl: new Uri(App.GoogleApiAuthorizeUrl),
            redirectUrl: new Uri(App.GoogleApiRedirectUrl2),
            accessTokenUrl: new Uri(App.GoogleApiAccessTokenUrl),
            getUsernameAsync: null
        );

        auth.Title = App.GetTextFromKey("Login");
        auth.AllowCancel = false;

        auth.Completed += (sender, eventArgs) =>
        {
            if (eventArgs.IsAuthenticated)
            {
                string code = "";
                eventArgs.Account.Properties.TryGetValue("access_token", out code);
                Console.WriteLine("ac: " + code);

                App.GoogleApiAccesToken = code;

                eventArgs.Account.Properties.TryGetValue("refresh_token", out code);
                Console.WriteLine("rc: " + code);

                NavHelper.Nav.NavigateToValidationPageAction.Invoke();
            }
        };

        activity.StartActivity(auth.GetUI(activity));
    }

public Action NavigateToValidationPageAction
{
get
{
return new Action(() =>
{
App.LoginOk = true;
NavPage.Navigation.PopModalAsync();
}
});
}
}

@BrunoVT1992
Copy link
Author

10-23 15:38:04.813 I/MonoDroid(21116): UNHANDLED EXCEPTION:
10-23 15:38:04.853 I/MonoDroid(21116): Android.Views.WindowManagerBadTokenException: Exception of type 'Android.Views.WindowManagerBadTokenException' was thrown.
10-23 15:38:04.853 I/MonoDroid(21116): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <IL 0x00011, 0x00068>
10-23 15:38:04.853 I/MonoDroid(21116): at Android.Runtime.JNIEnv.CallVoidMethod (intptr,intptr) [0x00062] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.18-series/0ef616ae/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:491
10-23 15:38:04.853 I/MonoDroid(21116): at Android.App.Dialog.Show () [0x00043] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.18-series/0ef616ae/source/monodroid/src/Mono.Android/platforms/android-14/src/generated/Android.App.Dialog.cs:2497
10-23 15:38:04.853 I/MonoDroid(21116): at Xamarin.Utilities.Android.ActivityEx.ShowError (Android.App.Activity,string,string) <IL 0x00048, 0x001e7>
10-23 15:38:04.853 I/MonoDroid(21116): at Xamarin.Utilities.Android.ActivityEx.ShowError (Android.App.Activity,string,System.Exception) <IL 0x00021, 0x00147>
10-23 15:38:04.853 I/MonoDroid(21116): at Xamarin.Auth.WebAuthenticatorActivity.m__1 (object,Xamarin.Auth.AuthenticatorErrorEventArgs) <IL 0x00017, 0x000cb>
10-23 15:38:04.853 I/MonoDroid(21116): at Xamarin.Auth.Authenticator/c__AnonStorey2.<>m__0 () <IL 0x00024, 0x000cf>
10-23 15:38:04.853 I/MonoDroid(21116): at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.18-series/0ef616ae/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
10-23 15:38:04.853 I/MonoDroid(21116): at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.18-series/0ef616ae/source/monodroid/src/Mono.Android/platforms/android-14/src/generated/Java.Lang.IRunnable.cs:71
10-23 15:38:04.853 I/MonoDroid(21116): at (wrapper dynamic-method) object.bbb4e52b-b564-45a7-a4c2-7012ae96822f (intptr,intptr) <IL 0x00011, 0x0003b>
10-23 15:38:04.853 I/MonoDroid(21116): --- End of managed exception stack trace ---
10-23 15:38:04.853 I/MonoDroid(21116): android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@41d42dc8 is not valid; is your activity running?
10-23 15:38:04.853 I/MonoDroid(21116): android.view.WindowManager$BadTokenEx10-23 15:38:04.863 I/MonoDroid(21116): at android.view.ViewRootImpl.setView(ViewRootImpl.java:705)
10-23 15:38:04.863 I/MonoDroid(21116): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:453)
10-23 15:38:04.863 I/MonoDroid(21116): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:351)
10-23 15:38:04.863 I/MonoDroid(21116): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:171)
10-23 15:38:04.863 I/MonoDroid(21116): at android.view.Window$LocalWindowManager.addView(Window.java:558)
10-23 15:38:04.863 I/MonoDroid(21116): at android.app.Dialog.show(Dialog.java:282)
10-23 15:38:04.863 I/MonoDroid(21116): at mono.java.lang.RunnableImplementor.n_run(Native Method)
10-23 15:38:04.863 I/MonoDroid(21116): at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
10-23 15:38:04.863 I/MonoDroid(21116): at android.app.Activity.runOnUiThread(Activity.java:4649)
10-23 15:38:04.863 I/MonoDroid(21116): at android.app.10-23 15:38:04.863 I/MonoDroid(21116): at mono.java.lang.RunnableImplementor.n_run(Native Method)
10-23 15:38:04.863 I/MonoDroid(21116): at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
10-23 15:38:04.863 I/MonoDroid(21116): at android.os.Handler.handleCallback(Handler.java:615)
10-23 15:38:04.863 I/MonoDroid(21116): at android.os.Handler.dispatchMessage(Handler.java:92)
10-23 15:38:04.863 I/MonoDroid(21116): at android.os.Looper.loop(Looper.java:155)
10-23 15:38:04.863 I/MonoDroid(21116): at android.app.ActivityThread.main(ActivityThread.java:5454)
10-23 15:38:04.863 I/MonoDroid(21116): at java.lang.reflect.Method.invokeNative(Native Method)
10-23 15:38:04.863 I/MonoDroid(21116): at java.lang.reflect.Method.invoke(Method.java:511)
10-23 15:38:04.863 I/MonoDroid(21116): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
10-23 15:38:04.863 I/MonoDroid(21116): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
10-23 15:38:04.863 I/MonoDroid(21116): at com.android.internal.os.ZygoteIn10-23 15:38:04.863 I/MonoDroid(21116): at dalvik.system.NativeStart.main(Native Method)
10-23 15:38:04.873 E/mono-rt (21116): Stacktrace:
10-23 15:38:04.873 E/mono-rt (21116):
10-23 15:38:04.873 E/mono-rt (21116):
10-23 15:38:04.873 E/mono-rt (21116): =================================================================
10-23 15:38:04.873 E/mono-rt (21116): Got a SIGSEGV while executing native code. This usually indicates
10-23 15:38:04.873 E/mono-rt (21116): a fatal error in the mono runtime or one of the native libraries
10-23 15:38:04.873 E/mono-rt (21116): used by your application.
10-23 15:38:04.873 E/mono-rt (21116): =================================================================
10-23 15:38:04.873 E/mono-rt (21116):
10-23 15:38:04.873 F/libc (21116): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 21116 (m.randstad.meta)
The program 'Mono' has exited with code 0 (0x0).

@jsauve
Copy link
Owner

jsauve commented Oct 23, 2014

What Android API level?

@BrunoVT1992
Copy link
Author

My app supports android 4.0 and above

@jsauve
Copy link
Owner

jsauve commented Oct 23, 2014

If you ARE using a very recent API level, I'm interested to see if you get the same type of exception when running one of the Xamarin.Forms samples: https://github.com/xamarin/xamarin-forms-samples

Try a few out and see what you get. If you're consistently seeing the same error, it may be a problem with APIs in the newest API level.

Full disclosure: I'm really not an Android expert of any kind (yet).

@jsauve
Copy link
Owner

jsauve commented Oct 23, 2014

Is that 4.0 what you're TARGETING in the app settings? Is that the only API level that you have installed?

@BrunoVT1992
Copy link
Author

I only have it with this app. The code works in iOS but not android. I have only api level 14 in use.

@jsauve
Copy link
Owner

jsauve commented Oct 23, 2014

When I built this sample, I only had Android API level 18 (Android 4.3 Jellybean) installed. No other API levels were installed.

@BrunoVT1992
Copy link
Author

Ok, I will try this tomorrow when I am back at work, I will let you know what happens.

@jsauve
Copy link
Owner

jsauve commented Oct 23, 2014

Cool. I'm interested to hear.

@BrunoVT1992
Copy link
Author

So, I tried different android api levels and I get the same error in all of them. Now I get this error trace:

An unhandled exception occured.
10-24 12:19:58.663 D/libc (11763): pt_debug : pthread_create->start_routine=0x402ad509, tls=0x59a5cf00, arg=0x5d270b40
10-24 12:19:58.663 D/libc (11763): pt_debug : __thread_entry->func=0x402ad509
10-24 12:19:58.663 D/libc (11763): , tls=0x59a5cf00, arg=0x5d270b40
The program 'Mono' has exited with code 0 (0x0).

@BrunoVT1992
Copy link
Author

So I narrowed the error down to the pagerenderer where I implement the xamarin auth component.

@BrunoVT1992
Copy link
Author

More specific, it crashes from the moment it loads my redirect url

@asanka-indrajith
Copy link

anyone found a solution to this. I too getting this error.

@davidesan
Copy link

Up Up Up :-)

I'm getting the same error with Facebook authentication.
It seems to happen on the redirection after the successfull authentication (I received the facebook token).

I get this error with this sample and on my own project.
I tried compiling for Android 6 and 7.

Can someone help me with this ??

Pleeeeeeeeeeeeease

@davidesan
Copy link

That error went away when I modified my returnUrl by the Facebook one (https://www.facebook.com/connect/login_success.html).
Previously I used a custom one. (y) (y) (y)

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

No branches or pull requests

4 participants