I want to implement tomb-stoning in my WP7 app and this app is not based on MVVM Pattern. Can any one refer me any good example of that to implement that. So I can maintain states of my app with some generic class.
Here are a few links that do pretty well explaining it:
This one does a good job explaining the different states that you have to manage, including the difference between suspended and tombstoned. http://lnluis.wordpress.com/2011/09/25/fast-application-switching-in-windows-phone/
Shawn Wildermuth is really good, and shows you in this video how to implement. http://vimeo.com/14311977
Here's a blog post that explains in good detail http://xna-uk.net/blogs/darkgenesis/archive/2010/11/08/there-and-back-again-a-tombstoning-tale-the-return-of-the-application.aspx
And this one is from the Windows Phone Developer Blog: http://windowsteamblog.com/windows_phone/b/wpdev/archive/2010/07/15/understanding-the-windows-phone-application-execution-model-tombstoning-launcher-and-choosers-and-few-more-things-that-are-on-the-way-part-1.aspx
Basically, when you want to tombstone, you need to use the Application_Deactivated event to store your variables in isolated storage, and use the Application_Activated event to retrieve them. With the advent of Mango (last fall), you should put a test in Application_Activated, to see if the app is coming from a suspended state.
if (!e.IsApplicationInstancePreserved)
{
//do stuff to restore from tombstoned
}
EDIT to add another example: Maybe this additional simple example will help you. http://dotnet-redzone.blogspot.com/2010/09/windows-phone-7-scrollbar-position.html
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
// Remember scroll offset
try
{
ScrollViewer viewer = ((VisualTreeHelper.GetChild(listBox, 0) as FrameworkElement).FindName("ScrollViewer") as ScrollViewer);
State["scrollOffset"] = viewer.VerticalOffset;
}
catch { }
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
object offset;
// Return scroll offset
if (State.TryGetValue("scrollOffset", out offset))
listBox.Loaded += delegate
{
try
{
ScrollViewer viewer = ((VisualTreeHelper.GetChild(listBox, 0) as FrameworkElement).FindName("ScrollViewer") as ScrollViewer);
viewer.ScrollToVerticalOffset((double)offset);
}
catch { }
};
}