Android hardware back button not working in --prod

I use platform.registerBackButtonAction in my ionic app its work in normal apk but if create --prod it not give the name of the active page please help how to solve ?

Have a look to this topic if it’s not already done :slight_smile:

1 Like

Helpful…Thank you for sharing


I have the same problem, have you solved this?

Thank you :slight_smile:

Did you read the linked issue which describes the problem? The bottom line is that it is a mistake to write any code that depends on the string names of classes or methods - it will break in production.

1 Like

Thank you. I’ve got it to work now. My problem now is that I don’t know how to determine if an active view is an overlay such as modal or alert dialog. Do you have any idea?

Here is my code

    this.platform.registerBackButtonAction(() => { 
      let nav = app._appRoot._getActivePortal() || app.getActiveNav();
      let activeView = nav.getActive().instance;

      if (activeView != null) {
        if (nav.canGoBack()) {
            if (activeView instanceof PageTwo) {
                // do something
            } else {
        } else if (activeView.isOverlay) {
        } else {
          let alert = this.alertCtrl.create({
            title: 'Ionic App',
            message: 'Do you want to close the app?',
            buttons: [{
              text: 'Cancel',
              role: 'cancel',
              handler: () => {
                console.log('Application exit prevented!');
              text: 'Close',
              handler: () => {