2
votes

Let's say i have 3 Xaml views and i use a MasterDetailPage and NavigationPage to navigate back and forward to those pages. Page A -> Page B -> Page C -> ...

I use PushAsync to perform the navigation. No big deal...

I implemment that in two ways:

1 - Create a new instance of those views every time on navigation:

await Navigation.PushAsync(new Views.PageA());

2 - Create a static property (at App view) for each page and i use that for navigation:

public static Views.PageA PageA 
    {
        get
        {
            if (_pageA == null)
            {
                _pageA = new Views.PageA();
            }

            return _pageA =;
        }
    }


await Navigation.PushAsync(App.PageA);

Is there another way to do that? Use static or new instance every time?

My concern it's about performance and memmory usage.

Please let's your answear with your opinion and some code will be apreciated.

1
Are you testing it on Android?Ali Bahrami
@AliBahraminezhad in both iOS and Adroid simulators and devicesFabio Silva Lima
I don't if it happens in both iOS and Android but Android Activitys will always get re-created. One of the workarounds is SingletonAli Bahrami

1 Answers

0
votes

The best way is to use push and pop. you can use pushmodalasync to create new root page (navigation stack count = 1 in this case). and poptorootasync to turn back to your root page(navigationstack[0]).