Dealing with Login / Main screens problem

I just studied LoginDemo example for Xamarin Samples and trying to get it work.

iOS

Setting RootViewController to another screen in iOS works normal. Sequence is first initialize UIWindow like always:

            window.RootViewController = App.GetLoginPage().CreateViewController();

            window.MakeKeyAndVisible();

            return true;

and then after button click change it like this:

            ((UIWindow)context).RootViewController = App.GetMainPage().CreateViewController();

            ((UIWindow)context).MakeKeyAndVisible();

It works, but after this funcions like DisplayAlert and DisplayActionSheet stop working correctly. On some ContentPage i have code like this:

                removeItem = new ToolbarItem(App.__("Remove"), null, async () => {
                    var action = await DisplayAlert(App.__("Remove"), App.__("Are you sure you want to remove record?"), App.__("Yes"), App.__("No"));

                    if (action) {
                        App.Database.RemoveModel((GenericModel)BindingContext);

                        await Navigation.PopAsync();
                    }
                }, ToolbarItemOrder.Default, 0);

and after changing RootViewController it show alert 3 times and after that throws error with message: "
System.InvalidOperationException: The underlying Task is already in one of the three final states: RanToCompletion, Faulted, or Canceled."

Android

I run LoginDemo example and it works like it is presented: login page is CarouselPage, main page is MasterDetailPage. After changing login and main page to ContentPage it stop works and SetPage has no affect or screen just dissapearing (blank dark screen).

I tried to use workaround like Activity.Finish() and Activity.StartActivity() like this:

            ((AndroidActivity)context).StartActivity(new Intent((AndroidActivity)context, typeof(MainActivity)));
            ((AndroidActivity)context).Finish();

but again DisplaySheet and DisplayAlert stop working and thows and unhandled exception.

Sign In or Register to comment.