
There are 2 types of states you want to save on windows phone 7. One is when user leaves your application and another one is when your application is tombstoned (deactivated by launching some other application from shell, like phone is ringing, phone is locked and so on).
In a first case persistent data is saved into Isolated storage. Using of isolated storage is covered deeply in a number of places on net. So, in this case I put as a reference following
link.
Small hint: all the data you save to isolated storage must be serializable.
Another hint - how to check is entity seriazable or not -
private static bool IsSerializable(T obj)
{
return ((obj is ISerializable) ||
(Attribute.IsDefined(typeof (T), typeof (SerializableAttribute))));
}
In a case another app forces your application closing deactivation event occurs and your handler on this event in app.xaml is executed. Keep in mind following - you have
only 10 seconds to save your transient data. If you don't save them in 10 seconds data is discarded and exception raises.
Hint: In this case data is saved into IDictionary<string,object> property called State on PhoneApplicationPage class. Keep in mind following - "The state is only accessible during or after the OnNavigatedTo(NavigationEventArgs) method is called. Also during or before the OnNavigatedFrom(NavigationEventArgs) method is called. If you implement it too early or too late it will throw an exception. You should not use this property for excessive storage as there is a limit of 2MB for each page and 4MB for the entire application."
Cheers