Reputation: 254
I'm developing with Cordova 3.x an app that need to runs on background when you press the HOME button, on Android I have in my config.xml the following line:
<preference name="exit-on-suspend" value="false" />
This works well on my Android emulator, when I press HOME button the apps continues on background but when I test on my real device the apps only runs on background too few seconds...
Any Solution? Thanks! :-)
Upvotes: 2
Views: 1644
Reputation: 2229
The preference exit-on-suspend
is only supported by iOS. According to a PhoneGap developer:
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.
A possible option is listening to the pause
event and then exiting the app when it occurs:
<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>
Upvotes: 1