Back button of Android device does not work

Good morning…

I added to my ionic v2 app an registerBackButtonAction() where :

if(page==x){ pop } else { setRoot(HomePage) }

When i do “ionic cordova run android” the app works fine on my android device, but when i do “ionic cordova build android --prod --release” and upload the app to play store the “setRoot” function does not work. Do you have any idea why this is happening??


Noone has any idea guys??

Could you display your code and not pseudo code?

this.platform.registerBackButtonAction(() => {
} else {
let view = this.navCtrl.getActive();
} else if(“HomePage”){
} else {


So a couple of idea:

  • Does it work when you build your app ionic cordova build android --prod and test the APK on your phone respectively could you reproduce the same problem without having to deploy in store? If yes, then you could add some alert("something); to debug

  • If only this.navCtrl.setRoot(...) isn’t working maybe you could try to use

  • Do you unregister your action too? It seems not, I would

    1. save the registration state

    this.unregisterCustomBackActionFunction = this.platform.registerBackButtonAction(() => {…

    1. and then unsubscribe if necessary like for example

    ionViewDidLeave() {
    if (this.unregisterCustomBackActionFunction != null) {

Hope that could help…don’t have any other idea

Thank you, I will try these ways!

1 Like

any update from this
I had same problem too

registerBack on device ready

when use ionic cordova run android --device //work fine
but use ionic cordova build android --prod //not work

Can you post your code?

I solved problem
I use to check active view
when debug mode its work fine

but when production mode has change because compiler

then i use to check active view

its back to work normally

1 Like

Great! I had problem with too! So i keep a global variable with the name of the active view and all work fine!

1 Like

Cool to hear you found your solution :slight_smile: You could know mark this issue as solved :wink:

please sen your code