Windows Phone apps moves between different application states:
- Apps are launched from Start Screen icon, apps menu or from deep link.
- User may close apps.
- The OS will suspend your app if it loses focus.
- Apps may be reactivated from a suspended state.
As you see in the above diagram, four events happens:
- Launching Event
- Deactivated Event
- Activated Event
- Closing Event
App Launching Event
The user taps a tile and starts the application. The application goes from the not running state to the launched state since it was started for the first time and the event handler Application_Launching is fired.
Code for this event is:
// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
}
private void Application_Launching(object sender, LaunchingEventArgs e)
{
}
App Deactivated Event
At this point either you continue working with your app or move away from your app by pressing the Start button or by launching another application, the event handler Application_Deactivated is fired, here one more situation could exist when Application_Deactivated is fired, let's say a call comes when using an application. In these types of situations the application goes into a dormant state and the good thing about this state is your application will automatically resume at the page where it is deactivated.
Code for this event is:
// Code to execute when the application is deactivated
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
}
App Activated Event
When you return to your app and resume it from a Dormant state, the event handler Application_Activated is fired.
Code for this event is:
// Code to execute when the application is activated
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
}
App Closing Event
When the user navigates backwards past the first page of an app and when the application is ended the Application_Closing event handler method is called.
Code for this event is:
// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
}
No comments:
Post a Comment