Search code examples
windows-phone-7tombstoning

When to save the state of the application for tombstoning?


I was wondering when is more appropriate to save the view model of the single pages.

I see two possibilities:

  1. Save the state of each page (it's viewmodel) everytime you navagitefrom it so that it is already saved if the application happens to be terminated and reactivated during the tombstoning process
  2. In the application deactivated event, go through all the pages that are in the navigation stack and save their state (their viewmodel) and then re-inject it in the application activated event.

Which is the correct way of handling it?

Thx Simone


Solution

  • Unfortunately the "best" time to save the state will depend on: the application; the complexity of the models used by each page; the interaction that each page supports; and the complexity of models shared between pages (at the app level).

    As a general rule I try and have a single model at the application level and persist that on activation/deactivation. The model for a page is a reference to part of the app level model and I only persist page specific information on navigation from/to a page.

    Examples of page specific information I persist are: entered but unsaved data; and scroll positions.