Exit app when press back key on phone


Anyone can help me, how to exit app when press back button with confirmation dialog box.


If you want to exit the application when the user confirms they really mean to close it, you can do this by checking to see if there are any views to actually go back to. If there aren’t you can alert the user and close the application when they click yes.

My example below is specific to a native hybrid app running in cordova, and uses the cordova notifications plugin to prompt the user.

$ionicPlatform.registerBackButtonAction(function () {
    var previousView = $ionicHistory.backView();
    if (!previousView) {
            "Are you sure you want to exit?",
            function(buttonIndex) {
                if (buttonIndex === 1) {
            'Confirm Exit',
            ['Yes', 'No']