Reputation: 1318
I'm working on a Windows 10 UWP app and I'm using the Template10 library. In the view model of the main page of my app, I have this code to try to handle suspend and resume:
public override void OnNavigatedTo(object parameter, NavigationMode mode, IDictionary<string, object> state)
{
if (state.Any())
{
NumberOfQuizQuestions = (int)state["QuizQuestions"];
state.Clear();
}
}
public override Task OnNavigatedFromAsync(IDictionary<string, object> state, bool suspending)
{
if (suspending)
{
state["QuizQuestions"] = this.NumberOfQuizQuestions;
}
return base.OnNavigatedFromAsync(state, suspending);
}
My question is: how can I test that this is working right? When I launch the app in the debugger, I have the Lifecycle Toolbar showing, so when I click "Suspend and shutdown" the code in OnNavigatedFromAsync()
runs and suspending
is true, which seems correct. But no matter how I try to launch the app, state
is empty in OnNavigatedTo()
. Is this expected?
Upvotes: 2
Views: 1660
Reputation: 1318
Thanks all. The problem is that Template10 uses the tile's ID to determine whether the launch is coming from a primary or secondary tile - if the tile's name is "App", it's the primary tile. In this case, I was using an upgraded project from Windows Phone 8.0, and for some reason my Package.appxmanifest had an Application tag with an Id that was not "App".
Upvotes: 0
Reputation: 10201
The way I quickly and reliably test/debug a resume scenario on a Windows 10 PC is as follows:
When you start the debugging session in step 3, Visual Studio will first compile and deploy your application. Of course, since the application is running, it must be first suspended and then terminated.
Then the application is started again, with the debugger attached, and the previous execution state is "terminated". Place your breakpoints and debug.
Upvotes: 4
Reputation: 363
You could deploy your application to a Windows 10 Mobile Emulator or an actual device. Then you can just run the app, go to your startscreen and return to it after a while to trigger the different states. This will not break your debugging session.
Upvotes: 0