Activate vs Tombstoning

Jan 15, 2011 at 7:18 AM

I have a WP7 page that inherits from the screen class and also overrides the OnActivate method (I assume this is the correct way to do this when using the base class, as opposed to just implementing the IActivate interface).

    public class SampleViewModel : Screen

        // other stuff

        private ComplexType _detail;

        [SurviveTombstone( SerializeComplexType = true)]
        public ComplexType Detail
            get { return _detail; }
            set { _detail = value; }

        protected override void OnActivate()

            if ( Detail == null )
                Detail = _dataService.GetDetail( Key );



My problem is I haven't found a good way to differentiate between the page activating because it is being loaded for the first time through navigation, and being activated because it is being resurrected from tombstoning.

Ideally I'd leverage the CM tombstone support to reload my Detail property but the trouble is that this seems to happen after the OnActivate method is called. This means my code ends up having to call the _dataService method which I'd prefer to avoid.


Jan 15, 2011 at 2:49 PM

What is I add a global flag that is set to true at app startup if resurrection is taking place. Then set to false after resurrection completes. Would that help?

Jan 16, 2011 at 5:17 AM

I managed to work around the problem by hooking into the OnViewLoaded method, as it appears by the time that fires the resurrection code has been run.