Android hardware back button

Well, how can i program what action the android hardware button should do in my app?
Every time i click it, my app is closed.

Anyone have an idea?

This is not implemented yet. See this file:

And this issue:

While waiting for the the Ionic implementation, the back button action can be overridden by defining an event listener for the backbutton event Cordova provides:

platform.ready().then(() => {
      document.addEventListener('backbutton', () => {
          console.log('Back button tapped');
      }, false);

Simply providing an event listener prevents the app from closing.

1 Like

Hi, have you an idea of how to use this to trigger the back action when in a nested/pushed page? it should do nothing if in a root page.

Nailed it, kind of, this should work when calling with sidemenus, but when calling this.platform.exitApp() it should close the app window, but all i get is a white screen, any idea how do i close the full app?:

import {App, IonicApp, Platform, NavController} from 'ionic-framework/ionic';
class MyApp {
  @ViewChild('rootNavController') nav: NavController;
  init() {
    this.platform.ready().then(() => {
      // console.log('Platform ready');
      // ----------------- Disable native back button--------------------
      document.addEventListener('backbutton', () => {
        if (!this.nav.canGoBack()) {
      }, false);

And in the html:

<ion-nav id="nav" #rootNavController [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>

Hi, glad it helped!

As for exiting the app, try replacing



and see if that works?


Tried that but the typescript linter says that navigator has no member app.

I think that’s just a problem with missing definitions, ie. it would work if it got past the linter.

I’m not a typescript expert, but there seem to be type definitions for cordova available at

Installing those would probably fix the linting error.

It actually works, it minimizes it which is an expected behavior, i have a tsd.json so i just need to install the tsd for Cordova right?

But which one? cordova? cordova-ionic?
I installed both but still the same, the linter jumps in my face.

I’m just guessing here since I don’t know much about typescript, but I’d say try cordova since the function you’re looking for is part of the core cordova functionality and not related to Ionic.

Late edit, the error remains even after installing both.

thanks luchillo17 , thanks Klasu
it work like a charm

The cordova tsd doesn’t include the toast plugin tsd, at the end i added manually to the tsd.d.ts an interface to Plugins in order to add the toast plugin.

Even though this is a month later…FYI, if you haven’t fixed this sort of issue before do this:

  1. Add a typings folder to your app root: e.g. app/typings

  2. Add a file called pluginshackyhacky.d.ts

  3. Add:

    interface /PhoneGapNavigator extends/ Navigator {
    app: any;

for properties you need extended for TypeScript to compile

  1. Add the whatever.d.ts to the compile in the tsconfig.json:

    “files”: [

You can see that I’ve also included the phonegap.d.ts file which includes a lot of missing properties/variables that allows TypeScript to compile without errors.

Hope this helps anyone having this problem.


whats content of phonegap.d.ts?

1 Like

Thanks, maybe this should be default file for ionic base app?

Some of this has been rendered unnecessary now with ionic native. Although not all of it, so I just comment out the bits as and when they are no longer needed.

Note: you still need to actually install the plugins required, ionic native is just a wrapper to make the syntax all nice and cosy for typescript and angular 2.