Search code examples
template10

Template10 - return user to the main page after resuming


Let's assume that my UWP app gets suspended and it is not used for a long time. When a user opens the app again (previous ApplicationExecutionState is Suspended or Terminated), I don't want the user to be navigated to the page he/she was viewing last (it became irrelevant since then), but instead do a fresh navigation to the main page. How can I do this using Template10?

It seems that when the user returns to the app, Template10 always returns the user to the page which was being viewed last. I tried overriding the OnResuming method in App.xaml.cs, however it had no effect.


Solution

  • I had this problem. I solved saving a bool property like ItWasSuspended in the LocalSettings of my app. When the OnResumming is activated I set to True this property or when the launched event was raised I set this property false.

    Finally in my pages in the OnNavigatedTo I get the value of this property if this property is true I navigate to the main page and I clear the back stack.

    Here is how to use the local settings

    https://msdn.microsoft.com/library/windows/apps/windows.storage.applicationdata.localsettings.aspx

    you can clear the back stack doing something like this

    this.Frame.BackStack.Clear();
    

    please mark this answer if it's useful for you!

    Best regards