Reputation: 170
I have made an app using intel xdk. The default behaviour of mobile's inbuilt back button redirects me on the page according to history. It behaves just like a web browser back button, because my code is in html5 format.
However, I want my app to exit/quit on click of back button. I am not any of the using cordova plugins.
I want to use back button to quit application. How can i do this.
Upvotes: 1
Views: 3179
Reputation: 29655
In cordova, when the device is ready, you can add an even listener to the back button like this:
document.addEventListener("backbutton", backButtonPressed, false);
Now the JavaScript backButtonPressed()
function will be called when the user presses the back button, so you just need to define it in your code, and use navigator.app.exitApp()
inside of it to exit the app. The resulting code would look like this:
function backButtonPressed() {
// Optionally, processes before quitting the app: save variables, log changes, etc.
...
// exit the application
navigator.app.exitApp();
}
Upvotes: 3