简体   繁体   中英

How to manage the onClose of windows phone 8.1 application

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM