Search code examples
androidangularionic4

Device back button event in ionic4 not working


I want to use the device back button event in ionic4 to do something but it not work.

my app.component.ts

export class AppComponent {
  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar
  ) {
    this.initializeApp();
    this.backButtonEvent()
  }
  backButtonEvent() {
    this.platform.backButton.subscribeWithPriority(2, () => {
      console.log("clicked to the back button")
    });
  }
}


Solution

  • You can catch hardware back button event like this

    this.sub = this.platform.backButton.subscribeWithPriority(9999, () => {
     // Do your stuff here
    });