How to close application using button ionic

The question was on Ionic 2 so you can’t use $scope


I cant use $scope in Ionic2

1 Like

This is the correct way in ionic 2


<button (click)="exitApp()">Close application<button>


import {Platform} from 'ionic-angular';

@Page({ /*...*/ })
export MyPage {
  constructor(platform: Platform) {
    this.platform = platform;

I just want to add a few notes to the following answer:

  • An additional Cordova plugin might be needed: does not work on iOS, only Android. On iOS, Apple does not allow apps to programmatically exit. It can be done through iOS Objective-C side but there’s a good chance this app will be rejected in Apple app store.

  • Therefore, I would not recommend you to do it and to rethink your UI instead:

Hi Tushar!

This is the way it work for me on Android

Best regards.


import 'es6-shim';
import {Component, Inject, ViewChild} from '@angular/core';
import {Platform, NavController,ionicBootstrap} from 'ionic-angular';
import {StatusBar} from 'ionic-native';
import {TabsPage} from './pages/tabs/tabs';
import {LoginPage} from './pages/login/login';

import {DataService, fb} from './lib/data.service';

  template: `
               <ion-nav #rootNavController [root]="rootPage"></ion-nav>`,
export class MyApp {
  @ViewChild('rootNavController') nav:NavController;
  private rootPage:any;

  constructor(public _data:DataService, private platform:Platform) {
    this.rootPage = TabsPage;

    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.


      document.addEventListener('backbutton', () => {
               let activeVC = this.nav.getActive();
               let page = activeVC.instance;

               if (!(page instanceof TabsPage)) {
                 if (!this.nav.canGoBack()) {
                   console.log('Exiting app due to back button press at the root view');
                   return navigator['app'].exitApp();
                 } else if (page instanceof LoginPage) {
                   console.log('Saliendo de la aplicacion para evitar ingresar sin registrarse');
                   return navigator['app'].exitApp();
                 console.log('Detected a back button press outside of tabs page - popping a view from the root navigation stack');
                 return this.nav.pop();

               let tabs = page.tabs;
               let activeNav = tabs.getSelected();

               if (!activeNav.canGoBack()) {
                 console.log('Exiting app due to back button press at the bottom of current tab\'s navigation stack');
                 return navigator['app'].exitApp();

               console.log('Detected a back button press - popping a view from the current tab\'s navigation stack');
               return activeNav.pop();

      }, false);



The plugin describe here, is not longer available, another way to do it on Android?

this.platform.exitApp() still works for me

this.platform.exitApp() doesn’t work :frowning:

What happens? Any errors?

Never mind I got it to work. my apk was not up to date. Thanks @andrewgy8.
BTW Do you know a method to hide the application ?

but not on ios i was unable to do that on ios emulator

this.platform.exitApp(); Is not working anymore since Ionic V4. What is the new way to do this ?

1 Like

@MrWhite : try



Thanks It worked like a charm

Hi this is giving run time error to me in Ionic 4 "core.js:15724 ERROR TypeError: Cannot read property ‘exitApp’ of undefined’. Anything wrong with below code?

ionViewWillLeave() {
if (this.commonService.checkLogin) {
if (this.router.url === ‘/app-landing’) {
if (this.router.url === ‘/login’) {
return navigator[‘app’].exitApp();

It is also working. i just tested in my android device.


Hope you know:
import { Platform } "ionic-angular";
and all

Have you tested in ionic 4?. Because in ionc 4 this.platform.exitApp() giving below error “Property ‘exitApp’ does not exist on type 'Platform”

Swap with navigator[‘app’].exitApp() as suggested many times before

1 Like

I am using ionic 3 and tested ionic 3 only.

I am using and many suggested :

It is working fine.

Track issue


thanks a lot it works