Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 228595

Exit app when press back key on phone

$
0
0

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) {
        navigator.notification.confirm(
            "Are you sure you want to exit?",
            function(buttonIndex) {
                if (buttonIndex === 1) {
                    ionic.Platform.exitApp();
                }
            },
            'Confirm Exit',
            ['Yes', 'No']
        );
    }
});

Viewing all articles
Browse latest Browse all 228595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>