Sun
Sun

Reputation: 4718

SuspensionManager Error when application has more than 1 page in windows 8 XAML/C# app

I'm writing a windows 8 XAML/C# app and have a little problem with the session manager.

Within my App.xaml.cs my OnSuspending method looks like this:

    private async void OnSuspending(object sender, SuspendingEventArgs e)
    {
        var deferral = e.SuspendingOperation.GetDeferral();
        //TODO: Save application state and stop any background activity
        await SuspensionManager.SaveAsync();
        deferral.Complete();
    }

I have registed my rootFrame with the SuspensionManager in the OnLaunched method in App.xaml.cs:

SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

So, in the first page of my app I have overriden the SaveState method. It looks like this:

    protected override void SaveState(Dictionary<string, object> pageState)
    {
        Save(true);

        base.SaveState(pageState);
    }

When the application is suspended this method is called and it all works fine.

I have a 2nd page with the SaveState method the same as the first (so as above).

When I navigate to the 2nd page from my 1st page and suspend the application neither of the SaveState methods are called and the application crashes with the following error:

SuspensionManager failed: Unspecified error

Brilliant!! Not much information there!!

So, do I need to do anything different with the SuspensionManager with multiple pages?

Thanks in advance

Upvotes: 3

Views: 1515

Answers (1)

Sushil
Sushil

Reputation: 5535

SuspensionManager manager works with multiple pages - no issues. given the little context, i would suggest following:

  1. Have you made any changes to common files that are auto-generated when creating a vs project using grid app template? if yes - try creating a fresh project.
  2. Are you passing any parameter that is non-serializable in the frame.navigate call? it is unlikely since in that case - you can see in output window something like this - WinRT information: GetNavigationState doesn't support serialization of a parameter type which was passed to Frame.Navigate.

Upvotes: 2

Related Questions