Cordova插件后台模式:onactivate第一次无效(android)

时间:2016-05-25 08:34:27

标签: javascript cordova background ionic-framework background-mode

我试图在我的离子应用程序中使用背景模式插件,但我遇到了一个问题。

我想做与backgroundmode.onactivate的github项目自述文件中显示的内容相同的内容。 如果它仅在第二次进入后台时才起作用,那将完全正常。

如果有人对这个问题有任何了解,我很高兴听到这个问题:)

我的代码示例:

 $ionicPlatform.ready(function() {

document.addEventListener('deviceready', function () {
 // Android customization
 cordova.plugins.backgroundMode.setDefaults({ text:'Doing heavy tasks.'});
 // Enable background mode
 cordova.plugins.backgroundMode.enable();

 if(cordova.plugins.backgroundMode.isEnabled()){
     console.log('Hi, I am enabled. Signed : backgroundMode.');
   }

 // Called when background mode has been activated
 cordova.plugins.backgroundMode.onactivate = function () {
     setTimeout(function () {
         // Modify the currently displayed notification
         cordova.plugins.backgroundMode.configure({
             text:'Running in background for more than 5s now.'
         });
         console.log('Running in background for more than 5s now.');
     }, 5000);
 }
}, false);

注意:我的应用程序启动时,我确实得到了行Hi, I am enabled. Signed : backgroundMode.

1 个答案:

答案 0 :(得分:0)

我改变了解决问题的方法。我虽然无法理解这个错误:(

i