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?
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());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With