App Resuming event does not fire when application resumes in WP 8.1 download application

The application of my WP 8.1 store behaves very strange. The application resume event fires as expected when I move quickly and then return. But if I keep the application in the background for a while and when it returns, the application fires Constructor and OnNavigatedTo events instead of the resume event and has a black “Resume ...” screen for a few seconds (about 4 seconds). This is an app with the BackgroundAudio job. Even the example BackgroundAudio application from MS behaves like this. Does anyone know what's wrong here?

+5
source share
2 answers

I am developing a WP 8.1 application that also uses background audio assignment. Everything you explained is also with me.

If you see “Resume ...” for a few seconds, it means that your application was interrupted by the OS after it was suspended. In this case, the resume event will not fire because your application has been completely killed and must resume. Resume usually means that a paused (not completed) application resumes execution.

When your application is completed and then “resumed” from the application switch, your override of the Application.OnLaunched() method will be called using e.PreviousExecutionState == ApplicationExecutionState.Terminated . In this method, you must check if the previous execution state was “Completed”, and if so, restore the application to the state that was before the suspension. This gives the user the illusion that the application never stopped, and they can resume what they were doing at that time.

If you create a new Pivot App Windows Phone 8.1 project (for example), you will see that the application life cycle events are correctly executed in App.xaml.cs

The Resume App event fires as expected when I move quickly and then return.

This is the correct behavior. It will take several seconds after the application was programmed before the OS was suspended, so if you resume the application before the OS suspends it, it will simply resume from memory.

I'm not sure why background audio applications are more prone to termination. I even found that the Xbox Music app behaves the same way. We hope that in the next version of Windows Phone this problem will be addressed.


FYI here is the application lifecycle diagram from MSDN (I recommend you read this page for more information on the application lifecycle):

Application lifecycle

Resume occurs only from paused states.

+5
source

Whenever the application resumes from the background. There are two states that can be in:

  • Suspended: it resumes successfully, moving directly to OnNavigatedTo ; the constructor will not be called
  • Completion: the application will not start from the previous state of the remaining page, but instead it will load this page again; at this point you need to save the state while the application pauses to restore it now.
+1
source

Source: https://habr.com/ru/post/1206386/


All Articles