How to resume an app (Windows Runtime apps using C#/VB/C++ and XAML)
Learn how to refresh displayed content when the system resumes your app. The example in this topic registers an event handler for the Resuming event.
Roadmap: How does this topic relate to others? See:
- Roadmap for Windows Runtime apps using C# or Visual Basic
- Roadmap for Windows Runtime apps using C++
Register to handle the Resuming event, which indicates that the user switched away from your app and then back to it.
Public NonInheritable Class MainPage Public Sub New() InitializeComponent() AddHandler Application.Current.Resuming, AddressOf App_Resuming End Sub End Class
When your app handles the Resuming event, it has the opportunity to refresh its displayed content.
Public NonInheritable Class MainPage Private Sub App_Resuming(sender As Object, e As Object) ' TODO: Refresh network data End Sub End Class
Note Because the Resuming event is not raised from the UI thread, a dispatcher must be used to get to the UI thread and inject an update to the UI, if that's something you want to do in your handler.
The system suspends your app whenever the user switches to another app or to the desktop. The system resumes your app whenever the user switches back to it. When the system resumes your app, the content of your variables and data structures is the same as it was before the system suspended the app. The system restores the app exactly where it left off, so that it appears to the user as if it's been running in the background. However, the app may have been suspended for a significant amount of time, so it should refresh any displayed content that might have changed while the app was suspended, such as news feeds or the user's location.
If your app doesn't have any displayed content to refresh, there's no need for it to handle the Resuming event.
A note about debugging using Visual Studio: When your app is attached to the Visual Studio debugger, you can send it a Resume event. Make sure the Debug Location toolbar is being shown, and click the drop-down next to the Suspend icon. Then choose Resume.
On Windows Phone, the Resuming event is always followed by OnLaunched, even when your app is currently suspended and the user re-launches your app from a primary tile or app list. Apps can skip initialization if there is already content set on the current window. You can check the LaunchActivatedEventArgs.TileId property to determine if the app was launched from a primary or a secondary tile and, based on that information, decide whether you should present a fresh or resume app experience.
- How to activate an app
- How to suspend an app
- Application lifecycle
- Guidelines for app suspend and resume
- Application class