Android back button always get triggered even after closing the page

I have successfully changed the back button behavior on Android using this code in the page’s constructor

let backAction = platform.registerBackButtonAction(() => {
let alert = this.alertCtrl.create({
message: ‘Are you sure that you want to go back?. If you go back all data will be lost’ ,
buttons: [
{
text: ‘yes’,
handler: () => {
this.navCtrl.pop();
}
},
{
text: ‘no’
}
]
});
alert.present();
},1)

The problem is this code keeps triggered every time I press the back button even after going back or closing the page.
Anyone knows what the problem might be?

you register back button action for entire application not one page

platform.registerBackButtonAction

Thank you that makes sense. The key here is to register the normal behavior back before leaving the page :slight_smile: