0

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.

Milan Aggarwal
  • 5,104
  • 3
  • 25
  • 54
  • If you're saving too much data, probably your app is getting terminated before flushing data onto disk. `Deactivated` event has a timeout of 10 seconds, your application will be forcefully terminated if you exceed the limit. Check out `SaveDataToIsolatedStorage` and `GetDataAsync` in [this](http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff967547(v=vs.92).aspx) msdn article for a strategy to read/save data incrementally over application lifetime. – Arun M Sep 28 '12 at 06:08
  • The message is get is this `The type System.RuntimeType was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.` Not: I am not using System.RuntimeType anywhere in my project, it might be present in some System files internally. – Milan Aggarwal Sep 28 '12 at 06:33

1 Answers1

0

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.
Faster Solutions
  • 7,005
  • 3
  • 29
  • 45
  • so shall i open my homescreen only every time when my app resumes from tombstone state? i.e. start the flow from state 1? – Milan Aggarwal Oct 05 '12 at 03:27
  • When you resume you should return the user to where they were when the app tombstoned. When resuming you should redirect to the correct page and set the state of the page to what it was before the app was suspended. – Faster Solutions Oct 05 '12 at 10:27
  • But according to my app usage its difficult to maintain on which page the user is on. Thus I am directing the user to page1 everytime. Hoping the app gets tombstoned after a long time after suspension of the app. – Milan Aggarwal Oct 05 '12 at 14:15