most cases where this plugin is useful is to prevent the user from exiting the app before a certain condition is fulfilled, this is where the plugin gets useful especially when using the registerBeforeExit() method. See the example below.
these methods act globally and will affect the whole app so you need to unregister them manually after you don't need them.
Example1:
make sure user sees an alert before he leaves the app
message:'Press back '+this.bbcounter+' more times',
duration:3000,
position:'bottom'
}).present();
returnfalse;//cancel backbutton action
}else{
this.bb.unregisterAction('default');//unregistering function because we won't need it anymore
returntrue;//allow backbutton action
}
})
}
}
Methods
registerDefaultAction(f: Function)
register the function to be called whenever the back button is pressed. If your function returns true, the default back button behavior with be triggered, if your function returns false the default behavior will be canceled.
registerBeforeExit(f: Function)
register the function to be called whenever the app is about to exit upon hardware back button press. If your function returns true, the default back button behavior with be triggered and your app will exit, if your function returns false the default behavior will be canceled.
unregisterAction(type: string){
type
Description
default
unregister registerDefaultAction()
beforeexit
unregister registerBeforeExit()
unregisterAll()
reverts back button default behavior.
back()
emulate android back button (including potentially exiting the app).