How to exit the app?


#1

The document says:

ionic.Platform.exitApp()

, but it doesn’t work.


#2

in 5 years i’ve never seen an app with an exit / quit button!


#3

It doesn’t work in ? Android? iOS ? Chrome?

http://community.phonegap.com/nitobi/topics/how_to_exit_from_the_phonegap_app_on_android_and_ios


#4

@Calendee Oh, Thanks for your help. I’m sorry I didn’t express clearly the platform is, your link makes me understand it.


#5

hey i want to close the app when user on login screen and pressed back button …how i close or exit app .???


#6

This is what I did on a recent app built, Toaster service referred to below is just a wrapper for the cordova-plugin-x-toast functionality.

var warnedExit = false;

// capture all instances of the hardware back button and do some custom behaviors
$ionicPlatform.registerBackButtonAction(function(event) {
            // if we have reached the beginning of the history tree
            if (!$ionicHistory.backView()) {
                // check to see if we have warned them before
                if (!warnedExit) {
                    // stop the navigation if the App is about to exit
                    event.preventDefault();

                    // flag that we have warned the user
                    warnedExit = true;

                    // show the instruction to press back again to exit
                    Toaster.showLong('Press back again to exit.');

                    // give the user 3 seconds before switching the warned flag back to false and start all over again
                    $timeout(function () {
                        warnedExit = false;
                    }, 3000);
                } else {
                    ionic.Platform.exitApp();
                }
            } else {
                $ionicHistory.goBack();
            }
        }, 1000);

#7

if (navigator) navigator.app.exitApp();