我正在使用 Cordova 3.x 开发一个应用程序,当您按下 HOME 按钮时需要在后台运行,在 Android 上我在我的 config.xml 中有以下行:
<preference name="exit-on-suspend" value="false" />
这在我的 Android 模拟器上运行良好,当我按下 HOME 按钮时,应用程序继续在后台运行,但是当我在我的真实设备上测试时,应用程序仅在后台运行太少秒...
有什么解决办法吗?谢谢! :-)
最佳答案
仅 iOS 支持首选项 exit-on-suspend
。根据 PhoneGap 开发人员的说法:
We worked on this a little while ago, but unfortunately because of nature of Android Activities, exiting on suspend breaks various functionalities that use additional activities. For example, when you use navigator.camera.getPicture, when the camera activity is launched, the app's main Activity is suspended, which will exit if we're exiting on suspend.
一个可能的选择是监听 pause
事件,然后在它发生时退出应用程序:
<script src="phonegap.js"></script>
<script>
function onPause() {
navigator.app.exitApp();
};
function onDeviceReady() {
document.addEventListener("pause", onPause, false);
};
function onLoad() {
document.addEventListener("deviceready", lbmon.onDeviceReady, false);
};
</script>
</head>
<body onload="onLoad();">
</body>
关于android - 在后台运行的应用程序(Phonegap Cordova 3.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19052228/