OnActivated(bool preserved)

Nov 28, 2012 at 9:51 PM
Edited Nov 28, 2012 at 9:52 PM

I dont know if it was intended like that but i called PersistenceManager.Instance.OnActivated(true) in App.cs in the OnResuming Event but nothing happened, and the activated method on my ViewModel didnt get called.

I took a look into the PersistenceManager class and repositioned a bracket.

Old code:

public async Task OnActivated(bool preserved)
        {
            this._mode = ApplicationMode.Activated;
            this._appReady = true;
            if (!preserved)
            {
                await this.GetPropertiesFromStorage();
                // Initialise regiestered
                this.InitialiseRegistered(preserved);
            }
        }

New code:

public async Task OnActivated(bool preserved)
        {
            this._mode = ApplicationMode.Activated;
            this._appReady = true;
            if (!preserved)
            {
                await this.GetPropertiesFromStorage();
            }
            // Initialise registered
            this.InitialiseRegistered(preserved);
        }

I needed that to handle some data that could be changed while the app was suspended.

Coordinator
Nov 29, 2012 at 5:33 AM

Try passing in false. True indicates that the device has preserved state and doesn't need rehydrating.

cheers.

Nov 29, 2012 at 7:06 AM

If i would pass preserved= false the viewmodel wouldn't know if the app was just resumed or activated after termination. For example OnResume I just check for removed secondary tiles, onActivation after terminating i need to rebuild some references of my objects.

Coordinator
Nov 29, 2012 at 7:26 AM

I see what you mean. I'll check it tonight and check it against the phone behaviour too. Looks like your solution might be best.

Coordinator
Nov 29, 2012 at 7:26 PM

I remember looking at this on a different project I had this same issue on myself and actually made the same change but didn't update the source. Change now checked in, thanks for pointing it out.

Nov 29, 2012 at 8:27 PM

Nice, and thx for this library btw ;)