Hamid
Hamid

Reputation: 4440

Handling focus loss of application

I am attempting to handle the loss of focus of my application, either by a phone call or other event, and also by the pressing of the home key.

I have tried setting a flag in the OnNavigatingFrom/OnNavigatedFrom and OnNavigatedTo event handlers but each time the app starts (either after pressing home, or something else) it always seems to be resetting the flag.

Which are the correct events I should be using in order to correctly "pause" and subsequently "resume" my application if it loses focus?

Upvotes: 0

Views: 645

Answers (2)

cjds
cjds

Reputation: 379

Read this. This is a microsoft tutorial on how to save state.

It'll give you how to save your ApplicationData when it is tombstoned.

Basically edit the Application_Closing and Application_Activated methods in the App.xaml to save the data to the system using isolated storage.

Upvotes: 0

AlexMok
AlexMok

Reputation: 764

You should read the documentation about application lifecycle. When you press the Home button, or when you receive a phone call, the application is paused. If you pressed Home, you can then restore the application by pressing the back button.

to handle these events, in App.xaml.cs by default the methods are: Application_Activated and Application_Deactivated

Of course you can manage to store data before the pause, and restore it when application is restored.

This is called tombstoning.

What you need is described in the following links:

http://windowsphone7.vectorform.com/2010/11/16/wp7-application-lifecycle/

http://www.windowsphonegeek.com/articles/WP7-Application-Lifecycle-and-Tombstoning

Upvotes: 1

Related Questions