Disable android hardware back button function

How to disable android`s hardware backbutton fucntion on a particular view??

Try something like this in your run method:

$ionicPlatform.registerBackButtonAction(function () {
    if ($state.current.name == "yourParticularViewStateName") {
        return;
    } else {
        // handle back action, example:
        navigator.app.backHistory();
    }
}, 100);
3 Likes

Just a noob question, what would be the view state name? Where can I find this info?

Depends on your routing techniques. The default Ionic templates use $stateProvider in app.js to define the states, its urls, its controllers and its views.

The state name would be tabs.timesheet?

.state(‘tabs.timesheet’, {
url: ‘/timesheet’,
views: {
‘timesheet-tab’: {
templateUrl: ‘templates/timesheet.html’,
controller: ‘TimeSheetController’
}
}
})

Yes, it is the string in the first parameter of .state, in your case ‘tabs.timesheet’.

1 Like