# How to exit the app?

**URL:** <https://forum.ionicframework.com/t/how-to-exit-the-app/1528>\
**Category:** ionic-v1\
**Created:** [March 3, 2014, 8:35am UTC](https://forum.ionicframework.com/t/how-to-exit-the-app/1528 "2014-03-03T08:35:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lagoonwish](https://avatars.discourse-cdn.com/v4/letter/l/b5e925/32.png) [@Lagoonwish](https://forum.ionicframework.com/u/Lagoonwish)\
**Post date:** [March 3, 2014, 8:35am UTC](https://forum.ionicframework.com/t/how-to-exit-the-app/1528/1 "2014-03-03T08:35:29Z")

</div>

The document says:

```
ionic.Platform.exitApp()

```

, but it doesn’t work.

---

<div class="post-metadata">

**Author:** ![krur](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@krur](https://forum.ionicframework.com/u/krur)\
**Post date:** [March 3, 2014, 10:52am UTC](https://forum.ionicframework.com/t/how-to-exit-the-app/1528/2 "2014-03-03T10:52:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Calendee](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/calendee/32/13656_2.png) [@Calendee](https://forum.ionicframework.com/u/Calendee)\
**Post date:** [March 3, 2014, 1:04pm UTC](https://forum.ionicframework.com/t/how-to-exit-the-app/1528/3 "2014-03-03T13:04:53Z")

</div>

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](http://community.phonegap.com/nitobi/topics/how_to_exit_from_the_phonegap_app_on_android_and_ios)

---

<div class="post-metadata">

**Author:** ![Lagoonwish](https://avatars.discourse-cdn.com/v4/letter/l/b5e925/32.png) [@Lagoonwish](https://forum.ionicframework.com/u/Lagoonwish)\
**Post date:** [March 3, 2014, 1:52pm UTC](https://forum.ionicframework.com/t/how-to-exit-the-app/1528/4 "2014-03-03T13:52:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![varshil29](https://avatars.discourse-cdn.com/v4/letter/v/49beb7/32.png) [@varshil29](https://forum.ionicframework.com/u/varshil29)\
**Post date:** [August 29, 2016, 11:19am UTC](https://forum.ionicframework.com/t/how-to-exit-the-app/1528/5 "2016-08-29T11:19:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![IamAdamJowett](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/iamadamjowett/32/67679_2.png) [@IamAdamJowett](https://forum.ionicframework.com/u/IamAdamJowett)\
**Post date:** [December 4, 2016, 5:54am UTC](https://forum.ionicframework.com/t/how-to-exit-the-app/1528/6 "2016-12-04T05:54:45Z")

</div>

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.

```auto
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);

```

---

<div class="post-metadata">

**Author:** ![baviskarmitesh](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@baviskarmitesh](https://forum.ionicframework.com/u/baviskarmitesh)\
**Post date:** [December 6, 2016, 12:50pm UTC](https://forum.ionicframework.com/t/how-to-exit-the-app/1528/7 "2016-12-06T12:50:34Z")

</div>

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