Reputation: 386
I developed an app that is working fine on windows phone. The nature of the app is such that it need not support tombstoning. That is, a fresh instance can be started each time.
The question is how do i prevent tombstoning my app? For example, if a user clicks on start button while in the app, i need to terminate the app, so that when he hits back key, the app starts with a fresh instance.
Any help would be greatly appreciated! :)
Upvotes: 0
Views: 168
Reputation: 1032
You should be able to do this from the Application_Activated event. In preMango you would typically do something like this:
private void Application_Activated(object sender, ActivatedEventArgs e)
{
var state = PhoneApplicationService.Current.State;
if (state.ContainsKey("YourKeyName"))
{
// Typically rehydrate. Clear app state
}
}
In Mango you might need to use the IsApplicationInstancePreserved property as well. This property indicates when the data was preserved for you and you don't event need to load it. See http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.activatedeventargs.isapplicationinstancepreserved(v=vs.92).aspx.
So you would need to add something like this:
if (e.IsApplicationInstancePreserved)
{
// Clear State
}
Upvotes: 1
Reputation: 4268
In each page you have's OnNavigatedTo (Or you could override PhoneApplicationPage) just set a variable that has each page check return to the original page. From there, you can just restart as if it was the beginning.
Apologies if function names are not 100%, typing this without Visual Studio Available.
Some logic.. In App.xaml.cs
public static bool Activated = false;
ApplicationActivated()
{
Activated = true;
}
in each page:
public override void OnNavigatedTo(object sender, NavigationEventArgs e)
{
base.OnNavigatedTo(sender,e);
if (App.Activated)
if (NavigationService.CanGoBack){
NavigationService.GoBack();
return; //remember that GoBack() is async and will not cause this function to end early! you must return
}
else { App.Activated = false; }
}
}
Upvotes: 1