0

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?

user2505650
  • 1,293
  • 6
  • 20
  • 38

1 Answers1

1

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

Alex Sorokoletov
  • 3,102
  • 2
  • 30
  • 52
  • Sorry I did not make myself very clear, I also pressed the WinButton and the search button but I returned to my the app it was like the app was running from the beginning – user2505650 Dec 23 '13 at 16:43
  • Following your example, did you implement LoadViewModelFromAppState method to load data? Also, you can debug deactivation and tombstoning and see if the ScrollOffset is really stored to and read from state on these events? – Alex Sorokoletov Dec 23 '13 at 16:47
  • Yes i implemente this method, can you please try to compile this code and see if it works? – user2505650 Dec 23 '13 at 16:53
  • In your example it's not enough items to make a scroll offset. I've added a bit more items, and in tombstoning it works. Make sure you check this checkbox http://www.scottlogic.com/blog/archive/2011/10/ForceTombstone.png What I noticed that scroll position is restored but not exactly at the same point. You might try this method but still the result is not exact. ItemsPanel.ScrollOwner.ScrollToVerticalOffset((double)State[ScrollOffsetKey]); – Alex Sorokoletov Dec 23 '13 at 17:11
  • Indeed the the scroll position is restored with your line of Code. But there is something else that i would like to know , When I re launch my app there is this image of a clock how can I remove this? – user2505650 Dec 23 '13 at 17:35
  • This is a default splash screen. Here is a documentation about it. http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff769511(v=vs.105).aspx To cut the long story short, you need to replace SplashScreenImage.jpeg with a new one of 480x800 pixels. – Alex Sorokoletov Dec 23 '13 at 21:56