Question

If I lock my phone while running my application and unlock it say after 30 minutes or 60 minutes, my screen appears blank. All my data (its a huge list compare it to a user's twitter feed) which was in an Observable collection in my ViewModel has disappeared. When I refresh I get NullReferenceException. Note that I am not handling any state save while locking and unlocking the phone. Is that the reason for the loss of my data? How can I handle it? Since there is a limit on the state data which can be saved of 4Mb Max, will it affect the functioning of my application even if I do implement it?

[Update]

I have tried the following things:
1) http://www.scottlogic.co.uk/blog/colin/2011/05/a-simple-windows-phone-7-mvvm-tombstoning-example/
2) http://www.scottlogic.co.uk/blog/colin/2011/10/a-windows-phone-7-1-mango-mvvm-tombstoning-example/
and many more.

The problem which I now face is that my application's viewModel contains an observable collection which I have binded to the UI. This observable collection is a collection of my user-defined class which contains complex data members. One of them is a dictionary. When i try to save my viewModel using XMLSerialization it throws an error as XML serialization doesn't support Dictionary.

I have also tried to write my viewmodel after Data contract serialization onto the IS during App_Deactivated and retrieve it on App_Activated. But my collection is null on resume. On opening the IS file it shows that the collection was not written onto the file. Am I missing some key ingredient in-order to solve this problem?

Note: I need my list. I cannot refresh data.

Was it helpful?

Solution

I'd suggest that this is the wrong approach.

Tombstoning is designed to allow you to save your state, not your data. You want to store the following:

  1. The page you're currently on
  2. The parameters, if any, that were used to get your list of data that you are currently showing
  3. Any selection state (has the user selected a row, etc)
  4. Any page state (is it in edit-mode, etc)

Not all of these things will apply, but it should provide you with an idea of what you should be storing.

This will be a significantly smaller set of data using simple data types rather than large chains of complex objects.

So:

  1. Store the properties/parameters that you use to get your data
  2. When the app resumes go get your data again using the params. If this take a while give the user some form of progress notification. If you can't accurately do this then display activity on the screen until the load finishes so the user knows that something is happening.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top