I am currently working on a HTML5 web application and packaging it with Cordova (phonegap) 1.7.
My goal is to customize the behavior of the Android back button so that instead of closing the application by default, it navigates back using window.history.back(). How can I prevent Android from terminating the default activity when the back button is pressed?
I have noticed that the "Back button pressed!!!!" message appears in the logcat before the application closes, indicating that the method is being executed beforehand.
Here is what my code looks like at the moment:
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
document.addEventListener("backbutton", function(e) {
console.log("Back button pressed!!!!");
window.history.back();
}, false);
}
EDIT: I am open to any suggestions on how to simulate the functionality of window.history.back() directly from the DefaultActivity.java Android class, if such an approach is feasible!