Hi,
With that code, you close any overlay (alert, popover, modal), any page if there is a previous page.and move the app in background if there is no previous page :
constructor(public platform: Platform, public app: App) {
platform.registerBackButtonAction(() => {
let nav = app._appRoot._getActivePortal() || app.getActiveNav();
let activeView = nav.getActive();
if (activeView != null) {
if (nav.canGoBack()) {
nav.pop();
} else if(activeView.isOverlay) {
activeView.dismiss();
} else {
backgroundMode.moveToBackground();
//this.closeApp();
}
}
});
}
I do not use that code in production for the moment but I tested it with an Alert, modal page and popover and that did the job but I still have to test it with a loader (I fear it closes the loader even if you do not want to) and I will have to find a trick for that.
So check if it works for you and feel free to improve and share the code