On Android, when you’re on your home/default app screen, you may want to exit the app when you hit the device’s back button.
Here’s a snippet to add to your theme’s functions.js that allows to do that:
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown() {
//Retrieve app's history
var history = App.getHistory();
//Check that there's only one screen in history (the current one):
if ( history.length === 1 ) {
//Check that this element is the default (home) screen:
var history_screen = history[0];
if ( TemplateTags.getDefaultRouteLink().replace('#','') === history_screen.fragment ) {
//Only one element in history and this element is default screen: exit app on back button:
navigator.app.exitApp();
return;
}
}
//History has at least one previous element: just go back to it:
navigator.app.backHistory();
}