Here is the quick article about to explain how to exit from the android application when user press back button.
Well, you guys know that most Android applications do not provide an “Exit” or “Quit” button.Back Button in android devices manages history of the previous page. It’s a way to get back to the previous page but sometimes in the big app, it create issue especially when maintain value using session.
So, Here is the easiest way to convert back button to exit from the app.Let’s see the function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { document.addEventListener("backbutton", function (e) { e.preventDefault(); navigator.notification.confirm("Are you sure want to exit from App?", onConfirmExit, "Confirmation", "Yes,No"); }, false ); } function onConfirmExit(button) { if(button==2){ //If User select a No, then return back; return; }else{ navigator.app.exitApp(); // If user select a Yes, quit from the app. } } |
The simple one core function is used to exit from android from an app and it will close an app.
Must Read:
Save Image/File into sd card in Android using PhoneGap
To setup SQLite for Android-Phonegap application
Display Text Format Proper in IPHONE+ANDROID
As always, thanks for reading. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.
Comments (2)