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??
Thanks…
Noone has any idea guys??
Could you display your code and not pseudo code?
this.platform.registerBackButtonAction(() => {
if(this.menuCtrl.isOpen()){
this.menuCtrl.close();
} else {
let view = this.navCtrl.getActive();
if(view.component.name==“WelcomePage”){
this.platform.exitApp();
} else if(view.component.name==“HomePage”){
this.navCtrl.setRoot(WelcomePage);
} else {
this.navCtrl.pop();
}
}
});
Thx.
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 this.app.getRootNav().setRoot(...
-
Do you unregister your action too? It seems not, I would
- save the registration state
this.unregisterCustomBackActionFunction = this.platform.registerBackButtonAction(() => {…
- and then unsubscribe if necessary like for example
ionViewDidLeave() {
if (this.unregisterCustomBackActionFunction != null) {
this.unregisterCustomBackActionFunction();
}
}
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
I solved problem
I use view.component.name to check active view
when debug mode its work fine
but when production mode view.component.name has change because compiler
then i use view.id to check active view
its back to work normally
1 Like
Great! I had problem with view.component.name 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
You could know mark this issue as solved 