Question

Current scenario stands like this:

  1. User opens my app
  2. Background audio agent starts playing
  3. User goes back to start screen
  4. Audio keeps playing from the background audio agent
  5. User kills the application from the "task bar" (the closing button in upper right corner)
  6. Background audio agent keeps playing.

I need to achieve following:

  • Close the audio background agent when the user kills the application (I know that I can use the close method on the backgroundaudioplayer but I need to call this when the application is killed/exited).

Questions:

  • Is there any event besides: Application_Deactivated / Application_Closing when the user truly exits/kills the application?
  • If there is no event like mentioned above - can I tell from Application_Deactivated / Application_Closing when the user really exits/kills the application?

Thank you

Was it helpful?

Solution

there is no way to detect when an app got closed by the task switcher or system. Usually apps keep tombstoned until they get either reactivated or killed. You have to do all the clean-up work in the Application_Closing and Application_Deactivated events.

This has one simple reason: When an application lies in the background it is freezed and cannot execute code. Whenever the user or the system kills it (to get more memory for example) the app and all its data get completely wiped out of the memory. Without notifying your app and without giving it the chance to gain performance (which would be counterproductive).

So you just have the chance to use the Application_Deactivated event when the user tap the start button or another app is launched or the Application_Closing event when the user closes the app via back button.

Read this if you need additional information about the Windows Phone 8 Application lifecycle.

Beside this a user would expect that the background audio is still running after he closes the application. A podcast for example should also play when I closed the podcast app. What kind of audio are you talking about? Maybe we can find a smart solution...

OTHER TIPS

The only events you can react to are Closing and Deactivated. So here,you can call BackgroundAudioPlayer.Instance.Close() in "Application_Closing" event only.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top