I'm practicing with Cordova. on Android, using also jQuery and jQuery Mobile.
I've a slide menù in my Example App. I check if this menù is open when the variable "global_isOpen".
This, with "menubutton", works perfectly:
document.addEventListener("menubutton", function(e){
if(global_isOpen) {
closeMenu();
}
else{
openMenu();
}
}, false);
But I've a problem with "backbutton". This is the code:
document.addEventListener("backbutton", function(e){
if(global_isOpen) {
closeMenu(); //is ok
}
else{
navigator.app.backHistory(); //this is the problem
}
}, false);
the navigator.app.backHistory();
goes to the previous page, but if I'm already on the first page, should come out from the app, exactly like the normal back button of android.
How can I check if I am already on the first page?
I don't have to check if I'm on the home page, because I could go back on the menu. I try to explain better with a scheme.
Example: openApp ---> homePage -> page1 -> page2 -> homePage -> page2 With "backbutton", I should do: page2 -> homePage -> page2 -> page1 -> homePage ---> closeApp