Hardware back button closes the app before executing the expected behavior

#1

Hello, I am so new to Ionic but I could create a working app but now I am finding it difficult to handle hardware back button properly,

this.platform.registerBackButtonAction(() => {
      if (!this.navCtrl.canGoBack()) {
          this.backgroundMode.moveToBackground();
        }
        this.navCtrl.pop()
    },5);

I added that code to my platform.ready in app.component but the Application goes to backgorund when I click on the hardwarebackbutton the onOpening the app again the page goes back.

Please Any hint would help, I am so stuck.