0

in my Application when logging out, I remove all Credentials and call Application.Current.MainPage = new AppShell(); and I'm wondering if this is causing memory leaks or if I'm meant to do that.

From my understanding that is the way to go when I don't want the user to be able to navigate back.


EDIT:

In my application the user should only see all pages when he is logged. All pages (except login page) use following class:

public class LoggedContentPage : ContentPage
    {
        private readonly WebService _webService = new WebService();
        protected override async void OnAppearing()
        {
            if (! await _webService.IsAuthenticated())
            {
                Application.Current.MainPage = new LoginPage();
            }
        }
    }

In turn my Login page uses:

bool success = await _webService.Authenticate(userCred);
if (success)
{
    Application.Current.MainPage = new AppShell();
}

Pressing the "back" button should not take the user back to the previous page in this case. What is the recommended way of navigating like this?

  • I don't think it's a good approach, I believe you can manage that otherwise, could you precise your requirement in more details "I don't want the user to be able to navigate back" ? – Cfun Apr 11 '21 at 11:40
  • Does [How can you restrict/control the navigation routes the user can visit based on login status/role?](https://stackoverflow.com/q/65186262) answers your requirements ? – Cfun Apr 11 '21 at 13:41
  • yes, particularly this line `await Shell.Current.GoToAsync("//Page2");` does. I will assume this is the proper way to go. Thanks – Fabian Kracher Apr 12 '21 at 08:58

0 Answers0