Ionic 5 - Disabling hardware back button Android

Maybe this can be helpful here as well (the code is also pasted below here): Disable back button on some of the views in ionic 4 - #5 by peterprmedia

I believe that you need to handle the subscription for the backButton inside the constructor method of your view class where you want to manipulate the normal actions of the hardware back button.

Also: If you only need the manipulation of the back button to be on the current view and not child views, then letting a boolean that’s affected by ionDidEnter and ionWillLeave might help distinguishing when we want to manipulate.

private isCurrentView: boolean;
private displayWarning: boolean;

constructor(private platform: Platform) {
   this.subscriptions.add(
      this.platform.backButton.subscribeWithPriority(9999, (processNextHandler) => {
		if (this.isCurrentView) {
			this.displayWarning = true;
            // Or other stuff that you want to do to warn the user.
		} else {
			processNextHandler();
		}
	})
}

ionViewDidEnter() {
    this.isCurrentView = true;	
}

ionViewWillLeave() {
    this.isCurrentView = false;
}

The priority of 9999 should make your code come first in the priority before the original actions, referring to what @EinfachHans mentioned earlier. And if you don’t want to stop all other actions from happening afterwards, then remember to add the processNextHandler parameter to the subscription and execute that method.