2

I have an application that I added a launch page to in the iOS and Android code. However when the app starts there is still quite a long delay while it fetches data. At this time there's a blank screen where I assume the app is still setting up the constructor.

I am trying to have an in-between page where that appears that loads the data. Not sure if this is the best way to do this but so far it's all that I have.

Here's the code that I have so far:

    public App()
    {
        InitializeComponent;
        MainPage = new NavigationPage(new Test.LoginPage())
        {
        };
    }

My Test.LoginPage is a simple empty Xaml page with this C# back end:

public partial class LoginPage : ContentPage
{
    public LoginPage()
    {
        InitializeComponent();
    }

    protected async override void OnAppearing()
    {
        await LongRunningTask();
        App.MainPage = new AppShell(); // I want to start a shell app
    }
}

 public partial class AppShell : Shell
 {
    public AppShell()
    {
        Routing.RegisterRoute("HomeTab/QHPage", typeof(QHPage));
        // etc

But the code has issues in that first of all I am not sure I am doing it correctly and secondly it says an object reference is required for App.MainPage.

Can anyone point me in the right direction and suggest how I could display this intermediate page and then display the real app pages?

Note that at some point I would also like to have a button on the login page that when clicked takes me to the app. But at this time I just want to get even the most simple version working so I am looking for some advice with that.

Alan2
  • 23,493
  • 79
  • 256
  • 450
  • I am having trouble in general getting an `async override void OnAppearing` to work for a Shell `ContentPage`. See https://stackoverflow.com/questions/62431815/xamarin-forms-page-displayalert-in-page-onappearing. My guess is it gets to the `await LongRunningTask();` line and silently dies, or is otherwise interrupted, before ever getting to the `App.MainPage` assignment. – Bondolin Jun 17 '20 at 17:42
  • 1
    Also see https://github.com/xamarin/xamarin.forms/issues/6486# – Bondolin Jun 17 '20 at 17:43

1 Answers1

1

The easy way is to set the AppShell as MainPage. The code below works for me.

 Application.Current.MainPage = new AppShell();

enter image description here

Wendy Zang - MSFT
  • 10,509
  • 1
  • 7
  • 17