locked
Windows Metro App Crashing when switched to other apps

    Question

  • Hi,

    We are developing a Windows app, we have completed 80% of the app, while testing it we find a issue - while to switching to other apps and coming back to our app. It crashing and starting from the flash screen thought we have navigated to 2-3 screens inside the app.

    Can anyone please guide what we are missing here, as far we see they no much helpful posts regarding this.

    It will be helpful if someone provide some code for this.

    Thanks in advance.

    Merry

    Monday, December 22, 2014 1:13 PM

Answers

  • Hi Merry,

    In your App.xaml.cs file make sure you have added OnSuspending event (refer the below code).

            /// <summary>
            /// Invoked when application execution is being suspended.  Application state is saved
            /// without knowing whether the application will be terminated or resumed with the contents
            /// of memory still intact.
            /// </summary>
            /// <param name="sender">The source of the suspend request.</param>
            /// <param name="e">Details about the suspend request.</param>
            private async void OnSuspending(object sender, SuspendingEventArgs e)
            {
                try
                {
                    var deferral = e.SuspendingOperation.GetDeferral();
                    await SuspensionManager.SaveAsync();
                    deferral.Complete();
    
                }
                catch
                {
                }
    
           }

    And make sure you have handled exceptions in Suspension Manager  SaveAsync() method

    Debug your code while suspending the app, refer the link below on how to debug the app while suspending

    http://msdn.microsoft.com/en-in/library/windows/apps/hh974425.aspx.

    Please mark this post as answer if your find it useful. Thanks

    • Marked as answer by Merry Koch Wednesday, December 24, 2014 5:46 PM
    Wednesday, December 24, 2014 11:26 AM

All replies

  • Hi Merry,

    What you are looking for is App suspend and resume.

    Please make sure you have followed the guidelines mentioned in the link below

    http://msdn.microsoft.com/en-us/library/windows/apps/hh465088.aspx

    Monday, December 22, 2014 1:17 PM
  • I think the issue maybe in NavigationTo or NavigationHelper_LoadState method. Please check them.

    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    Monday, December 22, 2014 3:15 PM
  • Thanks John,

    We verified with the App suspend and resume state, it seems to be correct.

    Is there any other thing we are missing?

    Thanks

    Monday, December 22, 2014 5:08 PM
  • Hi Bill,

    Can you please be specific, what could be the issue ? or any links will be helpful.

    Monday, December 22, 2014 5:10 PM
  • I just guessed, are there some variables' value become null when you switch back

    by the way, did it pass parameters when page navigate ?


    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。


    Monday, December 22, 2014 5:33 PM
  • Hi Merry,

    As mentioned by Bill Chung please please check for null variables.

    Also please refer this links on how to suspend an app - http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465115.aspx 

    and how to resume an app - http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465110.aspx 

    Hope this will be helpful.

    Monday, December 22, 2014 5:53 PM
  • Hi Mary,

    It will be helpful to figure out the issue, if you share with us the test case when your app is crashing.

    Monday, December 22, 2014 6:08 PM
  • Hi Bill,

    Thanks for the response, yes its passing the parameters between the pages.

    Tuesday, December 23, 2014 10:10 AM
  • What's the type of parameters ? There are some limitation.

    Frame.Navigate(TypeName, Object) method

    To enable frame state serialization using GetNavigationState, you must use only basic types for the navigation parameter, such as string, char, numeric, and GUID types. Otherwise GetNavigationState will throw an exception when the app suspends. The parameter can have other types if you do not use GetNavigationState.

    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    Tuesday, December 23, 2014 10:13 AM
  • Hi Shakir,

    Thanks for sharing the links again, we went through the links its useful, but we are not refreshing any code during the app resume state, the issue is while switching between the apps.

    One more question from the links you shared is do we need to write explicit code in App Suspend event handler. As far we refer from the Microsoft articles its mentioned that app will store this value by default, won't it?

    Tuesday, December 23, 2014 10:16 AM
  • My apologize for giving different replies, I am new this msdn, as mentioned above the test case is simple. We are running the app, navigating into the app screens say I am in 4th screen from the start screen then switching the app or opening a new app say App Store, after few seconds while switching back to my app, its crashing and starting again.

    Its not preserving its state as mentioned by the links you shared.

    Any idea or sample code, we really need help.

    Thanks in advance

    Merry

    Tuesday, December 23, 2014 10:23 AM
  • Hi Merry,

    In your App.xaml.cs file make sure you have added OnSuspending event (refer the below code).

            /// <summary>
            /// Invoked when application execution is being suspended.  Application state is saved
            /// without knowing whether the application will be terminated or resumed with the contents
            /// of memory still intact.
            /// </summary>
            /// <param name="sender">The source of the suspend request.</param>
            /// <param name="e">Details about the suspend request.</param>
            private async void OnSuspending(object sender, SuspendingEventArgs e)
            {
                try
                {
                    var deferral = e.SuspendingOperation.GetDeferral();
                    await SuspensionManager.SaveAsync();
                    deferral.Complete();
    
                }
                catch
                {
                }
    
           }

    And make sure you have handled exceptions in Suspension Manager  SaveAsync() method

    Debug your code while suspending the app, refer the link below on how to debug the app while suspending

    http://msdn.microsoft.com/en-in/library/windows/apps/hh974425.aspx.

    Please mark this post as answer if your find it useful. Thanks

    • Marked as answer by Merry Koch Wednesday, December 24, 2014 5:46 PM
    Wednesday, December 24, 2014 11:26 AM
  • Hi Shakir,

    Thanks it worked, actually we don't know that we can debug the code at App suspension event, the link was helpful.

    Thanks and Merry Christmas!!!

    Wednesday, December 24, 2014 5:46 PM