Share via


PhoneApplicationService.Deactivated Event

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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.

Syntax

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

Remarks

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.

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Platforms

Windows Phone

See Also

Reference

PhoneApplicationService Class

Microsoft.Phone.Shell Namespace