Question

I am building a MVVM Windows Phone 8 application.

I read this post to try to resolve tombstonning problems : http://www.scottlogic.com/blog/2011/10/03/a-windows-phone-7-1-mango-mvvm-tombstoning-example.html

This example implements Tombstonning on a MVVM application. The application generates a twitter feed in a listbox.

I changed the some lines of codes of this example as it deals with the old twitter api, but when I run the application, close it or activate Win or Search Buttons, and then re launch it again , the page state is not the same.

Here is what I changed in the view Model to simulate a new Twitter Feed :

j = new List<FeedItemViewModel>();
    j.Add(new FeedItemViewModel
    {
        Author = "Auth",
        Title = "Sample1",
        Id = 1
    });


    j.Add(new FeedItemViewModel
    {
        Author = "Auth",
        Title = "Sample2",
        Id = 2
    });
    j.Add(new FeedItemViewModel
    {
        Author = "Auth",
        Title = "Sample3",
        Id = 3
    });
    j.Add(new FeedItemViewModel
    {
        Author = "Auth",
        Title = "Sample4",
        Id = 4
    });
    j.Add(new FeedItemViewModel
    {
        Author = "Auth",
        Title = "Sample5",
        Id = 5
    });
    foreach (FeedItemViewModel t in j)
    {

        this._feedItems.Add(t);

    }
    public void Update()
        {
            this._feedItems.Add(new FeedItemViewModel
            {
                Author = "_Auth",
                Title = "_Sample",
                Id = 99
            });
        }

But when I close my application and re launch it , the state is not the same, for example the scroller position is not the same as when I left the application although there is a method in this sample to remember the scrolling position of the list.

Do you know why tombstonning is not working properly?

Was it helpful?

Solution

Closing has nothing to do with tombstoning.

Tombstoning/deactivation occurs when you press "Win" or "Search" buttons on the phone. You app becomes inactive, and home screen or search app (or any other, that's just an example) becomes active. Your apps goes to dormant or tombstoned state, depending on many things.

When you press back, active app closes and previously active app becomes active again. That is called activation.

When activation occurs, your app might be restored from dormant (everything is kept in memory, app is just paused) or from tombstoned state (system "relaunches" the app and restores navigation stack and current page, developer is responsible to restore all other state - variables, input data and so on).

So, the difference is that tombstoned app doesn't keep all the state inside and that's developer's task.

There is a good document on MSDN about Windows Phone App Lifecycle

You can learn how it works using this article with example - WP7 Application Lifecycle and Tombstoning

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top