Problem with AppMinimize and Android hardware back button

#1

Hello. I am working on improving the functionality of the Android hardware back button handling that I have in place and have run into an issue when using the AppMinimize plugin.

When I hit the back button on certain pages, I want the app to minimize instead of going back. I have managed to achieve this, but when I reopen the app the backward navigation that was previously intercepted takes hold.

When I reopened the app after minimizing it, I see the back animation as if the router outlet’s pop function has been run. This is not desired behavior because I do not want the back button to ever do anything but minimize the app on certain pages.

Here is the code I am using:

this.platform.backButton.subscribe(event => {
  if (this.router.url == "/home") {
    this.appMinimize.minimize();
    //  this.routerOutlet.pop();
    //  this.routerOutlet.pop(0);
    //  this.nav.navigateRoot(this.router.url, false);
    //  None of the above 3 attempted fixes have helped.
    //  I have also tried monitoring when this backbutton subscription function callback is called, and it is only called once total
  }else if(this.routerOutlet && this.routerOutlet.canGoBack()){
    this.routerOutlet.pop();
    // I have tried without this, it doesn't help
  }
});