Android hardware back button in ionic

Hello all,
in the tutorial for ionic 2 ionic 2 tutorial after clicking on an item the back button closes the app instead of going back to the list page I tried using platform

registerBackButtonAction but it didn’t work. here is the code I tried

import {Page, NavController, NavParams, Platform} from 'ionic-framework/ionic';
import {Inject} from 'angular2/core';
  templateUrl: 'build/pages/item-details/item-details.html'
export class ItemDetailsPage {
  constructor(@Inject(NavController) nav, @Inject(NavParams) navParams,
  @Inject(Platform) platform) {
    this.nav = nav;
    // If we navigated to this page, we will have an item available as a nav param
    this.selectedItem = navParams.get('item');
    this.platform = platform;
    // this.platform.onHardwareBackButton(function(e){
    //   e.preventDefault();
    //   return true;
    // });

Hardware back button support is a feature we have not added yet. It’s on our road map


Is there any approximate timeline for this to be implemented in Ionic 2? At the moment, this makes using Ionic 2 for an Android app much less viable.

1 Like

You can checkout our public road map here

I think this should be the most basic feature and important. Android users are used to the back button, and will just stop using the app if it closes on pressing the back button.
I am considering moving to ionic, and will not publish my app unless I am able to implement this.

This feature already exists in ionic V1. Since V2 is still beta, there’s still some features we need to work on.

I solved it for now. Read my quick blog post on it here:


1 Like

What is the expected due date for beta 3?

No set due date right now


I’m a tad confused, why is there documentation for this:$ionicPlatform/#onHardwareBackButton

Are you saying this will not work yet?


@nebrekab So that doc that you have linked to is for Ionic V1. We’re talking about Ionic V2

Or you could watch for the document event for back button and use it as you need, for example here’s mine from the init() method in the app.ts file inside platform.ready().then(() => {...}):

// ------------ Double back button press to exit---------------
      document.addEventListener('backbutton', () => {
        if (this.nav.canGoBack()) {
        if(!this.backPressed) {
          this.backPressed = true
'Presiona el boton atras de nuevo para cerrar', 'short', 'bottom')
          setTimeout(() => this.backPressed = false, 2000)
        // this.platform.exitApp()
      }, false);

Ah! A subtle but important detail :slight_smile:
Thanks for the reply. I’ll keep an eye on this, for the time being @Daveshirman fix worked.

His fix relies on alert while mine in toast notifications, both are valid options, it depends how you want the back button to work.

I have the same problem, i use ionic 2 beta 8 and here is my code:

this.platform.ready().then(() => {
         if (nav.canGoBack()) {nav.pop();}
         else {this.confirmExitApp(nav);}
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.

i tried on real device and the hardware back is disabled, it does nothing.
Any help please. I googled a lot for any example of use of registerBackButtonAction in ionic 2 but no result

hey guzs i also get same issue??any solution came??

Hey, I just worked through a similar problem that someone posted on my blog. You can find my answer to his (her?) question here, and the code implemented in a project on my GitHub. Hope it helps.

i write below code for back button handle but nothing happend

platform.registerBackButtonAction(() => {
console.log(‘in app.ts’);

i write this in all page. is there any issue to write in all page?


I’m tring to override the backbutton with:


goBack() {;

But I always get:
Uncaught TypeError: Cannot read property 'getRootNav' of undefined

Anyone has seen and solved this?


Maybe the app isn’t yet ready? Does it help to test the platform first?

For the record, to override the back button I did the following, works fine for me:

 onPageWillEnter() {
      this.platform.ready().then(() => {
        this.unregisterCustomBackActionFunction = this.platform.registerBackButtonAction(() => {
              // The special stuff I want to do and where I want to go

and then later, before leaving my view, to set back the back action to her default behavior