这是我的代码
//This is an event that fires when a PhoneGap application is put into the background. document.addEventListener("pause",onPause,false); //This is an event that fires when a PhoneGap application is retrieved from the background. document.addEventListener("resume",onResume,false); // Handle the pause event function onPause(){ console.log("pause : app is put into background"); } // Handle the resume event function onResume() { console.log("resume : app is put into foreground"); }
当我按下主页按钮时,控制台中没有日志,但是当我单击应用程序(将其置于前台)时,我的日志就是
2011-11-22 12:11:37.206 Event[644:207] [INFO] pause : app is put into background 2011-11-22 12:11:37.206 Event[644:207] [INFO] resume : app is put into foreground
解决方法
这是来自文档
In the pause handler,any calls that go through Objective-C will not work,nor will any calls that are interactive,like alerts. This means that you cannot call console.log (and its variants),or any calls from Plugins or the PhoneGap API. These will only be processed when the app resumes (processed on the next run-loop).