I'm experiencing odd behavior in the wp7 emulator.
I have a dead simple app that's mostly directly from the template generated by VS 2010.
From App.xaml:
<!--Required object that handles lifetime events for the application-->
<shell:PhoneApplicationService
Launching="Application_Launching" Closing="Application_Closing"
Activated="Application_Activated" Deactivated="Application_Deactivated"/>
Tombstoning code from App.xaml.cs:
private void LoadSettings()
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
ICollection<TicTacSpot> getSpots;
if (settings.TryGetValue<ICollection<TicTacSpot>>("spots", out getSpots))
{
Spots = getSpots;
}
if (Spots == null)
{
Spots = new List<TicTacSpot>();
}
}
private void SaveSettings()
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
settings["spots"] = Spots;
}
// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
LoadSettings();
}
// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
LoadSettings();
}
// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
SaveSettings();
}
// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
SaveSettings();
}
Seems straightforward enough. I set breakpoints in all these methods. When I hit F5 to deploy the app, the event handlers that are hit are:
Application_Launching()
Application_Deactivated()
Oddly, these are hit, even though the emulator doesn't show the app opening or closing.
In the emulator, I then open the app, play around, close it, then re-open it. I use both the "back" and "start" buttons to close it. Despite this, I am unable to get any event handlers to be hit again.
What am I doing wrong here?