document.addEventListener('deviceready', function () {
cordova.plugins.backgroundMode.setDefaults({
title: 'TheTitleOfYourProcess',
text: 'Executing background tasks.'
});
// Enable background mode
cordova.plugins.backgroundMode.enable();
// Called when background mode has been activated
cordova.plugins.backgroundMode.onactivate = function () {
// Set an interval of 3 seconds (3000 milliseconds)
setInterval(function () {
var dd = new date();
var h = dd.getHours();
var m = dd.getMinutes();
if(h == 2 && m ==50){
alert("2:50");
}
}, 3000);
}
}, false);
如果用户关闭程序,如闹钟或某些程序提醒,我怎么能让app仍然运行?
答案 0 :(得分:2)
将此行添加到config.xml
以启用后台活动
<preference name="KeepRunning" value="true"/>
答案 1 :(得分:1)