2

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.

Jan Kalfus
  • 5,422
  • 2
  • 30
  • 38

1 Answers1

2

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

RicardoPons
  • 1,323
  • 9
  • 14
  • I had the same idea. However, this feels a bit dirty. You need to put the same code on every page you don't want the user to be returned to - instead of handling this issue on an application level. Also, instead of using the local settings storage, I would advise using simply a static property in the App class, as storing the value into the settings seems like an overkill to me. Nevertheless, thank you for the answer :) – Jan Kalfus Feb 28 '16 at 10:28