Zack
Zack

Reputation: 1113

Windows phone 8 Fast Resume when Tombstoned

http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj735579%28v=vs.105%29.aspx According to the document when I use fast resume in windows phone 8 I can resume my App from main tile.

But when my app is tombstoned , for example, mainPage can navigate to ->pageA can naviget to->PageB, I deactived the app from PageA, then the app is tombstoned, when I click the Tile that navigate to PageB, it's strange that the app back to Page A .

How to fix this problem?

Upvotes: 1

Views: 1873

Answers (1)

flacnut
flacnut

Reputation: 1100

It sounds like you are not saving the application state before it is tombstoned. There are 4 events that are fired for preserving application state:

These are related to completely closing and reopening the application (eg: Phone restart)

  • Application_Launching
  • Application_Closing

These are related to tombstoning (task switching)

  • Application_Activated
  • Application_Deactivated

It sounds like what you need is the second one relating to activating / deactivating. These methods are placed in the Applications *.cs file and allow you to preserve and reinstate the ViewModel when tombstoning.

This is an example:

private readonly string ModelKey = "Key";

private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
  PhoneApplicationService.Current.State[ModelKey] = ViewModel;
}

private void Application_Activated(object sender, ActivatedEventArgs e)
{
  if (PhoneApplicationService.Current.State.ContainsKey(ModelKey))
  {
    ViewModel = PhoneApplicationService.Current.State[ModelKey] as FeedViewModel;
    RootFrame.DataContext = ViewModel;
  }
}

Upvotes: 1

Related Questions