Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigate to default page from OnResume()

In Xamarin forms, the OnResume event handler is on the Application class, which is not a NavigationPage, so you cannot do any navigation in OnResume. When my app resumes, if it has been asleep for more than 30 mins, I want it to go back to its home page, not resume to the page where it went to sleep. I have got the 30 minute trap in the OnResume, but I can't do the navigation. Can anyone suggest a way of doing this?

like image 823
Ric Avatar asked Jun 28 '15 15:06

Ric


1 Answers

by default, in a Forms app, you're storing the MainPage which should be a NavigationPage in this case.

public class App : Application
{
    public App ()
    {
        // The root page of your application
        MainPage = new NavigationPage {

So you can use it to get to the Navigation object.

protected override async void OnResume ()
{
    var nav = MainPage.Navigation;

    // you may want to clear the stack (history)
    await nav.PopToRootAsync (true);

    // then open the needed page (I'm guessing a login page)
    await nav.PushAsync(new LoginPage());
}
like image 119
Benoit Jadinon Avatar answered Oct 19 '22 03:10

Benoit Jadinon