PhoneApplicationService.Deactivated Event

July 28, 2014

Occurs when the application is being deactivated.

Namespace:  Microsoft.Phone.Shell
Assembly:  Microsoft.Phone (in Microsoft.Phone.dll)
XMLNS for XAML: Not mapped to an xmlns.

'Declaration
Public Event Deactivated As EventHandler(Of DeactivatedEventArgs)
<object Deactivated="EventHandler<DeactivatedEventArgs>" .../>

This event is raised when the user navigates away from the application, by taking an action such as pressing the Start button or by invoking a Launcher or Chooser. An application is also deactivated when the lock screen engages. Handle this event by preserving the application’s transient application state into the State dictionary, which you can restore in the handler for the Activated event if the application is reactivated. It is not guaranteed that the application will be reactivated. Therefore, it is a good practice to also save persistent state, such as settings and user data, to isolated storage in the handler for this event.

Applications are given 10 seconds to complete the Deactivated handler. If the event handler has not been completed before this time span has elapsed, the application is terminated. It is recommended that applications aim for 2 seconds for completing the handler to provide a large buffer for unexpected delays. Applications should incrementally save data to isolated storage and to the State property while the application is running to reduce the amount of data storage that needs to be performed in the Deactivated handler.

It is possible for your application to be activated without having been. For this reason, you should not destroy your application’s state in the handler for this event so that your application can resume without reestablishing state if it is activated without being tombstoned.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft