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

BadTokenException: Unable to add window -- token android.os.BinderProxy is not valid; is your activity running? #338

Closed
ericbrunner opened this issue Feb 16, 2017 · 6 comments

Comments

@ericbrunner
Copy link

commented Feb 16, 2017

Hi,

Please check all of the platforms you are having the issue on (if platform is not listed, it is not supported)

  • [] iOS
  • Android
  • [] UWP
  • PCL

App Type

Xamarin.Forms PCL with Platform specific Versions for Android and iOS

Version of OS(s) listed above with issue

Android OS 6.0.1

Phone Type

Samsung Galaxy : SM-A800F

Version of ACR UserDialogs Library

PCL: 6.3.5
Android: 6.3.6

Expected Behaviour

No crash when using ShowLoading.

Actual Behavior

If applicable, please include entire exception - type, message, stacktrace

Several times that exception is raised inside that code area:

   public async Task RefreshItemsAsync(bool showActivityIndicator, bool syncItems)
    {
        syncItems = syncItems && CrossConnectivity.Current.IsConnected;

        UserDialogs.Instance.ShowLoading("Daten werden geladen...", MaskType.Black);

        if (syncItems)
        {
            await OfflineSyncStoreManager.Instance.SyncFullLocalStoreAsync();
        }
        _truckAuftragOverviewViewModel.TruckAuftragOverviewItems =
            await _truckAuftragOverviewStore.GetTruckAuftragOverviewItemsAsync(false);

        _truckAuftragOverviewViewModel.LanguageItems =
            await OfflineSyncStoreManager.Instance.TagSpracheStore.GetTagSpracheItemsAsync(false);

        UserDialogs.Instance.HideLoading();
    }

Xamarin caused by: Java.Lang.RuntimeException: Unable to add window -- token android.os.BinderProxy@76b34a6 is not valid; is your activity running?
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <9ec32ab9a7034ada8fe3b809cead0e03>:0
at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00084] in <18084a75c66b422b845757415c15be1d>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002f] in <18084a75c66b422b845757415c15be1d>:0
at Android.App.Dialog.Show () [0x0000a] in :0
at AndroidHUD.AndHUD+<>c__DisplayClass26.b__24 (System.Object state) [0x0011f] in :0
at Android.App.SyncContext.Send (System.Threading.SendOrPostCallback d, System.Object state) [0x00025] in :0
at AndroidHUD.AndHUD.SetupDialog (Android.Content.Context context, AndroidHUD.MaskType maskType, System.Action cancelCallback, System.Func4[T1,T2,T3,TResult] customSetup) [0x00030] in <aebdb213571f458882a8594c4938e808>:0 at AndroidHUD.AndHUD.showStatus (Android.Content.Context context, System.Boolean spinner, System.String status, AndroidHUD.MaskType maskType, System.Nullable1[T] timeout, System.Action clickCallback, System.Boolean centered, System.Action cancelCallback) [0x000de] in :0
at AndroidHUD.AndHUD.Show (Android.Content.Context context, System.String status, System.Int32 progress, AndroidHUD.MaskType maskType, System.Nullable1[T] timeout, System.Action clickCallback, System.Boolean centered, System.Action cancelCallback) [0x0001d] in <aebdb213571f458882a8594c4938e808>:0 at Acr.UserDialogs.ProgressDialog.Refresh () [0x0008d] in <435daf83b740428697641f6937603702>:0 at Acr.UserDialogs.ProgressDialog.Show () [0x00010] in <435daf83b740428697641f6937603702>:0 at Acr.UserDialogs.AbstractUserDialogs.Progress (Acr.UserDialogs.ProgressDialogConfig config) [0x0001c] in <1c1daa10b89248f1b2ef0708f0d1d6bf>:0 at Acr.UserDialogs.AbstractUserDialogs.Loading (System.String title, System.Action onCancel, System.String cancelText, System.Boolean show, System.Nullable1[T] maskType) [0x0005c] in <1c1daa10b89248f1b2ef0708f0d1d6bf>:0
at Acr.UserDialogs.AbstractUserDialogs.ShowLoading (System.String title, System.Nullable`1[T] maskType) [0x0000e] in <1c1daa10b89248f1b2ef0708f0d1d6bf>:0
at trucker_rolsped.Pages.TruckAuftragOverviewPage.RefreshItemsAsync.d__13.MoveNext ():

I uploaded the full crash log from my HockeyApp account here

The above RefreshItemsAsync gets called in OnAppering event and from the background utilizing the Xamarin.Forms.CrossPlatform Connectivity Plugin fron that callback method.

    public async void PhoneConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
    {
        Page currentPage = null;

        try
        {
            MainPageCS masterDetailPage = Application.Current.MainPage as MainPageCS;

            if (masterDetailPage != null)
            {
                currentPage = masterDetailPage.IsPresented ?
                    masterDetailPage.Master.Navigation.NavigationStack.LastOrDefault() :
                    masterDetailPage.Detail.Navigation.NavigationStack.LastOrDefault();
            }

            MetricsManager.TrackEvent($"Connectivity-{MobileAppClient.CurrentUser.UserId}",
                new Dictionary<string, string>
                {
                    {"Connected", e.IsConnected.ToString()},
                }, new Dictionary<string, double>());

            if (!e.IsConnected)
                return;

            if (!App.TruckDriver.Authenticated)
            {
                App.TruckDriver = await DependencyService.Get<IAuthenticate>().SignIn().ConfigureAwait(false);
            }

            if (App.TruckDriver.Authenticated)
            {
                //Re-Sync the local-db DataStore with remote-db after Re-Connection
                await OfflineSyncStoreManager.Instance.SyncFullLocalStoreAsync().ConfigureAwait(false);

                if (currentPage == null)
                {
                    await MetricsManagerHelper.Instance.SendErrorToApplicationInsightsAsync("TruckerApp - No Topmost page found to be used for IRefreshLocalStoreTable based refresh.");
                    return;
                }

                var refreshEnabledPage = (currentPage as IRefreshPage);

                if (refreshEnabledPage == null)
                {
                    await MetricsManagerHelper.Instance.SendErrorToApplicationInsightsAsync($"TruckerApp - Page \"{currentPage.GetType().Name}\" has no IRefreshPage implementazion.");
                    return;
                }

                Device.BeginInvokeOnMainThread(async () => await refreshEnabledPage.RefreshItemsAsync(false, syncItems: false));
            }
        }

The last statement is the call. I use the Device.BeginInvokeOnMainThread(async () => await refreshEnabledPage.RefreshItemsAsync(false, syncItems: false)); to update UI.

Thanks for your time and any help.

best

Eric

@aritchie

This comment has been minimized.

Copy link
Owner

commented Feb 16, 2017

The exception pretty much says it all - you are calling for the loader when the activity isn't available.

@ericbrunner

This comment has been minimized.

Copy link
Author

commented Feb 17, 2017

Not helpful ! I removed that ShowLoading's from my callback invoker code. Next time I don't spend so much time to explain such detailed question and consider to remove your nuget at all. Its' the nugets job to check if a activity is running or not, NOT my code as the API user!

@aritchie

This comment has been minimized.

Copy link
Owner

commented Feb 17, 2017

There isn't anything I can do to check if the activity is good. You should wrap loading calls in a try/catch anyhow. The exception does state the issue, so you can post in detail all you want, I can't change the result.

If you come here again with your entitled attitude, I'll simply ban you. I don't get paid for any of this. If you don't like the result, go make something better instead of behaving like a spoiled child.

@aritchie aritchie added the not a bug label Feb 17, 2017

@aritchie aritchie closed this Feb 17, 2017

@ericbrunner

This comment has been minimized.

Copy link
Author

commented Feb 17, 2017

Relax. try-catch auf your code is a good starting point

@aritchie

This comment has been minimized.

Copy link
Owner

commented Feb 17, 2017

Relax?? Seriously....?? Don't come back

@ElderLars

This comment has been minimized.

Copy link

commented Nov 1, 2018

I am also having this problem. Iam calling
var acrResult = await UserDialogs.Instance.PromptAsync(message, title);
in my portable library. I dont have an activity there, only in the android project, right?
Is there another way for me to handle the situation? Can i just wrap it in a try catch and retry or will it try with the same activity again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.