Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Setting MainPage = NavigationPage during OnStart in Xamarin.Forms display a blank screen in Android

$
0
0

I have a Xamarin Forms Application where I'm setting the MainPage to NavigationPage during OnStart.
The NavigationPage is static (kept in memory for reuse).
When I press the back button in Android and go back to the app the OnStart method is executed again and the application displays a blank screen.
The repro: OnStart Static NavigationPage

public partial class App : Application
{
    private static readonly NavigationPage NavigationPage = new NavigationPage(new MainPage());
    public App ()
    {
        InitializeComponent();
    }

    protected override void OnStart()
    {
        MainPage = NavigationPage;
    }
}

If I do the same action in the constructor the application behaves as expected: there's no blank screen and the last page visited is displayed.
The repro: Constructor Static NavigationPage

public partial class App : Application
{
    private static readonly NavigationPage NavigationPage = new NavigationPage(new MainPage());
    public App ()
    {
        InitializeComponent();

        MainPage = NavigationPage;
    }
}

What is the difference between setting the MainPage in the constructor and in the OnStart method?


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>