问题描述
我正在尝试创建一个应用程序,该应用程序在可见时执行一些工作,而在它消失时执行其他工作.这通常通过页面可见性 api (http://css.dzone.com/articles/using-html5s-pagevisibility) 完成,但 Windows 8 目前不支持:http://msdn.microsoft.com/en-us/library/ie/hh673553(v=vs.85).aspx
有 onactivate 和 oncheckpoint 回调,但它们是针对流程生命周期的,不一定与应用可见性相关.具体来说,应用程序可以在暂停之前进入后台相当长的一段时间.
任何帮助将不胜感激.
-- 亨利
我想你想要 visibilitychange 事件.请参阅Document
文档此处.更多关于应用程序生命周期事件的信息这里.p><块引用>
应用可见性
当用户从您的应用切换到另一个应用时,您的应用不再可见,但仍处于运行状态,直到Windows 可以暂停它(大约 10 秒).如果用户切换远离您的应用,但在 Windows 之前激活或切换回它可以暂停它,应用程序保持在运行状态.
您的应用没有当应用可见性改变时接收一个激活事件,因为应用程序仍在运行.Windows 只是简单地切换到应用程序和从应用程序切换为必要的.如果您的应用需要在用户切换时执行某些操作来回,它可以处理 VisibilityChanged |msvisibilitychange 事件.
可见性事件没有序列化恢复或激活事件.不要以为这些事件会来按特定顺序.
I am trying to create an app which does some work when it becomes visible, and does other work when it goes away. This is typically accomplished with the page visibility api (http://css.dzone.com/articles/using-html5s-pagevisibility) but this is not currently supported in windows 8: http://msdn.microsoft.com/en-us/library/ie/hh673553(v=vs.85).aspx
There are callbacks onactivated and oncheckpoint but these are for the process lifecycle and are not necessarily related to app visibility. Specifically, an app can go to the background for quite some time before it is suspended.
Any help would be appreciated.
-- Henry
I think you want the visibilitychange event. See the Document
documentation here. More on application lifecycle events here.
App visibility
When the user switches from your app to another app, your app is no longer visible but remains in the running state until Windows can suspend it (for about 10 seconds). If the user switches away from your app but activates or switches back to it before Windows can suspend it, the app remains in the running state.
Your app doesn't receive an activation event when app visibility changes, because the app is still running. Windows simply switches to and from the app as necessary. If your app needs to do something when the user switches away and back, it can handle the VisibilityChanged | msvisibilitychange event.
The visibility event is not serialized with the resume or activation events. Don't assume that these events come in a particular order.
这篇关于如何判断 JS Windows8 Metro 应用程序是否可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!