Back Button Hardware Event Handler Can't Determine Overlay View

Hello Everyone,

I modified the functionality of hardware back button. It works on pages but it cannot determine whether an overlay views like modals and alert dialog boxes are present or not.

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 MultiRegistrationOne || activeView instanceof MultiRegistrationTwo || activeView instanceof MultiRegistrationThree) {
                // do something
            } else {
	           nav.pop();
            }
        } else if (activeView.isOverlay) {
          activeView.dismiss();
        } 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: () => {
                this.platform.exitApp();
              }
            }]
          });
          alert.present();
        }
      }
    });

I hope someone can help me with this :slight_smile:

Please anyone help me :cry: :cry:. I’ve been stuck on this for a week now.