简体   繁体   English

如何管理Windows Phone 8.1应用程序的onClose

[英]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. 因此,我想在应用程序关闭(不挂起)时将记录的值设置为“ false”,但是就像我说的那样,我找不到任何一种“关闭”方法来覆盖。
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. 在App.xml.cs的“ OnLaunched”方法中,则无法正常工作。

Define a handler vor the Application.Suspending event ( https://msdn.microsoft.com/en-us/library/windows.ui.xaml.application.suspending ). 通过Application.Suspending事件定义处理Application.Suspendinghttps://msdn.microsoft.com/zh-cn/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. 因此,没有关闭应用程序的特殊事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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