I am unable to use "pause" and "resume" events as described here: Events - Apache Cordova
My test article is working as it should on iOS, but not on Android. On iOS, when I leave the app by opening another app, or put my device to sleep, the "pause" event fires and when I come back, the "resume" event fires. None of this happens on Android.
My basic requirement is to execute some javascript on an interval. But, it doesn't make sense for the code to run when the app is not in the foreground. Has anyone else encountered a similar problem, or can suggest a workaround? (If possible, I'd like to avoid building a custom shell for my app.)
The javascript I'm testing with is:
$(document).ready(function() {
app.init();
});
var app = {
init: function() {
document.addEventListener('deviceready', app.onDeviceReady, false);
},
onDeviceReady: function() {
$("#container").append("<h2>onDeviceReady</h2>");
document.addEventListener("pause", app.onPause, false);
document.addEventListener("resume", app.onResume, false);
},
onPause: function() {
$("#container").append("<h2>onPause</h2>");
},
onResume: function() {
$("#container").append("<h2>onResume</h2>");
}
};