在 Windows Phone 8.1 XAML 中检测停用和应用程序关闭 [英] Detecting deactivation and app close in Windows Phone 8.1 XAML

查看:23
本文介绍了在 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 中,App 类中有 Application_DeactivatedApplication_Closing 方法(或在 Caliburn.Micro 中重写的方法 OnClose、OnDeactivate).

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).

唯一有趣的事件似乎是 SuspendResume,但是当我使用开始"按钮退出应用程序并使用后退"按钮返回时它们不会被调用,或者从列表中启动应用程序.

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 有哪些替代方案?

(设置 ActivationPolicy="Replace" 可以解决一半的问题,但我想这是不可能的,因为 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).

推荐答案

Suspending 事件将在您离开应用程序后立即调用,但不会在调试模式下调用.我已经构建了一个简单应用修改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:

  • Suspending 事件之前,OnNavigatedFrom 事件正在被调用,但是当您 Resume 时,OnNavigatedToem> 被 称为 - 参考:

  • 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天全站免登陆