How to manage the onClose of windows phone 8.1 application

98 views Asked by At

I would like to manage the behavior of my application when it closes (and not when it is suspended), but I couldn't find any method to override.
In this application, a user can log in with his profile: when he is in the main page of the application and presses back button, the app goes suspended and it's ok then that if it's resumed the user is still logged; what I want to do is that if the application is closed, the user won't be logged anymore, and if he opens the app again he has to log in again.
When the login is successful, I set local settings this way:

var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            localSettings.Values["Logged"] = true;

So I would like to set to "false" the value of logged whenever the application is closed (not suspended), but like I said I couldn't find any kind of "on close" method to override.
The only way I've found to achieve what I want is to set

var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            localSettings.Values["Logged"] = false;

in the "OnLaunched" method in App.xml.cs, but it's not working fine.

1

There are 1 answers

0
Wosi On BEST ANSWER

Define a handler vor the Application.Suspending event (https://msdn.microsoft.com/en-us/library/windows.ui.xaml.application.suspending).

The system suspends your app whenever the user switches to another app or to the desktop, and resumes your app whenever the user switches back to it. However, the system can also terminate your app while it is suspended in order to free up resources.

So there is no special event for closing the app.