I'm creating a jQuery Mobile app which is contained within a Titanium app's webview. When the Android back button is pressed, it exits the app rather than going to the previous page (not the best default behavior in my opinion.) I'm trying to get around this by executing the following code on app load:
document.addEventListener("deviceready", function () {
alert("adding back button event");
document.addEventListener("backbutton", function (e) {
alert("in back button event");
if ($.mobile.activePage.is('#homepage')) {
alert("exit app");
e.preventDefault();
navigator.app.exitApp();
}
else {
alert("go back");
navigator.app.backHistory()
}
}, false);
}, false);
Everywhere I see threads about this issue, they say to use the backbutton event, however it's not being fired at all. If I wrap it in a deviceready event, like above, then deviceready isn't called either. Is the webview somehow suppressing these events, or is there another way to do this with jQuery Mobile?