Actually, if you are using a mobione button you are better off using the properties on click and setting that to Run Javascript.
then you can assign any page using:
phoneui.gotoPage(‘#m1-pageName’);
as well as running any javascript or function. So you could use your function inside the onClick – Run Javascript:
function onBackKeyDown() {
alert(‘We will now go to a new page’);
phoneui.gotoPage(‘#m1-pageName’);
}
But, if you still need it here is the javascript go back code:
window.history.back()
Android does not really have an on exit call it uses.
But you could also try this as you may be trying to add the listener before the device is ready:
Add this to script to get device ready call:
document.addEventListener(“deviceready”, onDeviceReady, false);
Add event listener to back button and add your code to that call:
function onDeviceReady(){
document.addEventListener(“backbutton”, onBackKeyDown, false);
}
function onBackKeyDown(){
alert(‘back’);
return false;
}