检测失活和应用程序接近的Windows Phone 8.1 XAML [英] Detecting deactivation and app close in Windows Phone 8.1 XAML

查看:95
本文介绍了检测失活和应用程序接近的Windows Phone 8.1 XAML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了安全起见,我需要注销,当他们退出应用程序,并显示登录界面,当他们返回回用户。

For security reasons, I need to log out the users when they exit the app and show login screen when they return back.

在的Windows Phone 8和Windows Phone 8.1 Silverlight的有 Application_Deactivated Application_Closing 在App类的方法(或方法OnClose中,OnDeactivate在Caliburn.Micro覆盖)。

In Windows Phone 8 and Windows Phone 8.1 Silverlight there are Application_Deactivated and Application_Closing methods on the App class (or methods OnClose, OnDeactivate to override in Caliburn.Micro).

唯一有趣的事件似乎是暂停恢复,但是当我使用启动按钮退出应用程序,并取回使用后退按钮或启​​动列表中的应用程序,他们不叫。

The only interesting events seems to be Suspend and Resume, but they do not called when I exit the app using the Start button and get back using the Back button or launching the app from the list.

什么是Windows Phone的8.1 ​​XAML的替代品?

(设置 Activati​​onPolicy =替换将解决一半的问题,但我想这是不可能的,当WMAppManifest.xml不是事件的Windows Phone 8.1 XAML项目的一部分)。

(Setting ActivationPolicy="Replace" would solve half of the problem but I guess this is not possible, when WMAppManifest.xml is not event a part of a Windows Phone 8.1 XAML project).

推荐答案

挂起的事件会叫你导航刚过,离开这个程序,而不是在调试模式。我已经建立一个简单的应用程序 modyfing的 LocalSettings 的后的挂起的事件,然后获取信息。当的恢复

The Suspending event will be called just after you navigate away from the app, but not in debug mode. I've build a simple app modyfing LocalSettings upon Suspending event and then acquiring information when Resuming.

您可能已经注意到,但对于答案的完整性的考虑 - 一些言论:

You are probably aware, but for the sake of completeness of the answer - some remarks:


  • 之前的挂起的情况下,的 OnNavigatedFrom 的被称为事件,但是当你的简历的,在的OnNavigatedTo 的是不会称为 - 的参考

  • before Suspending event, the OnNavigatedFrom event is being called, but when you Resume, the OnNavigatedTo is not called - reference:

请注意在Windows Phone,OnNavigatedFrom()当应用程序暂停被称为。的OnNavigatedTo()当应用程序恢复不叫。

Note On Windows Phone, OnNavigatedFrom() is called when the app is suspended. OnNavigatedTo() is not called when the app is resumed.

要测试的挂起/恢复的与调试器,在使用的生命周期事件调试位置的标签 - 更多信息

  • to test Suspending/Resuming with debugger, use Lifecycle events in Debug location tab - more info

    引用的在Windows运行时应用程序生命周期应用

    这篇关于检测失活和应用程序接近的Windows Phone 8.1 XAML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆