Android device back button navigation


#1

Hi there,

Is it possible to specify to which view/state the back button of the android device should navigate to?

I have many nested views within my app and rather than the back button taking me to my previous view, I’d like it to take me to specific view such as “home”. I have been researching this but have yet to find questions/answers that match to what I am trying to do.

Any help would be appreciated, thank you!


#2

You could trap the back button and do a $state.go inside it


#3

What does it mean to trap the back button and how could I go about doing that? I’m not sure how to trigger the state.go event for the hardware backbutton. Thank you!


#4

You can add this inside the .run function of app.js

 $ionicPlatform.registerBackButtonAction(function (event) {
           $state.go('foo');
        
}, 100);

Whenever you press the back button of Android, this will make it go to the state named ‘foo’


#5

I will try this, thank you for your help!