如果应用程序空闲到10分钟,如何从启动屏幕启动

If app is idle till 10 minutes, how to start from splash screen

本文关键字:启动 屏幕 10分钟 应用程序 如果      更新时间:2023-09-26

我想写一个javascript代码,通过它在空闲状态下重新启动Phonegap应用程序,直到最后10-20分钟。我使用以下代码

$('document').ready(function(){
    var idleTime = 0;
    var idleInterval = setInterval(timerIncrement, 60000);
    $(this).mousemove(function (e) {
            idleTime = 0;
    });
    $(this).scroll(function (e) {
            idleTime = 0;
    });
    function timerIncrement() {
        idleTime = idleTime + 1;
        if (idleTime > 10) { // 20 minutes
            window.localStorage.removeItem("user_id");
            window.localStorage.removeItem("client_id");
            location.reload();
        }
     }
 });    

要再次显示闪屏,可以使用

navigator.splashscreen.show();

但是你也必须用代码隐藏它

setTimeout(function() {
    navigator.splashscreen.hide();
}, 2000);

使用此事件将睡眠时间值写入本地存储

document.addEventListener("pause", yourCallbackFunction, false);

当你的应用程序重新启动时,使用这个事件来检查睡眠时间值,以确定它是否超过10分钟

document.addEventListener("resume", yourCallbackFunction, false);

使用下面的代码来显示和隐藏你的闪屏,如果你的条件满足

navigator.splashscreen.show();
setTimeout(function() {
   navigator.splashscreen.hide();
}, 3000);

在cordova文档中查看事件详细信息