gpt4 book ai didi

javascript - 长时间暂停后恢复应用程序时如何处理场景(未终止)

转载 作者:行者123 更新时间:2023-11-29 15:43:15 25 4
gpt4 key购买 nike

我的应用程序显示它从网络服务中检索到的数据。假设我的应用程序进入挂起模式并长时间保持挂起状态。之后,当这个应用程序恢复时,我想再次查询网络服务并在应用程序中显示更多最新数据。问题是我不确定什么是处理这种情况的好地方。我有下面代码的简化版本。在下面的示例中,当我使用挂起和终止选项时,我在控制台窗口中获得了恢复,但是当我只执行挂起并在恢复之后,似乎没有调用任何函数。知道我可能做错了什么吗?

app.addEventListener("resuming", function (vt) {
console.log("resuming");
});

app.addEventListener("activated", function (args) {
console.log("activated");
if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
console.log("new launch");
} else {
console.log("resume");
}
}
});

app.oncheckpoint = function (args) {
console.log("suspended");
};

最佳答案

假设您对变量“app”的定义是示例应用程序中的标准:

    var app = WinJS.Application;

那么根据 MS documentation,您不能将该变量用于“恢复”或“暂停”事件上面写着:

Note Listeners for some Windows Store app events, like "suspending" and "resuming", cannot be added with this function. You must use Windows.UI.WebUI.WebUIApplication.addEventListener instead.

因此,正如该文档所说,您需要使用:

Windows.UI.WebUI.WebUIApplication.addEventListener("suspending", suspending, false);
Windows.UI.WebUI.WebUIApplication.addEventListener("resuming", resuming, false);

关于javascript - 长时间暂停后恢复应用程序时如何处理场景(未终止),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15776253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com