onHardwareBackButton question


#1

Hi!

I would like use onHardwareBackButton method, but doesnt work this code:
This code is in one controller

`starter.controller('ViewCtrl', function($scope,$state,$ionicPlatform) {...`
        $ionicPlatform.onHardwareBackButton(function() {
            if($state.current.name == 'view') { //in console **view** the state name
         		$state.go('app.comp');
        	};
        });

It must have something to work? Thanks


#2

in this view, i use a modal, when i open modal and tap on mobile back button, go to app.comp state, but why?
if modal close and tap mobile back button, exit the app…


#3

// Disable BACK button on home
$ionicPlatform.registerBackButtonAction(function (event) {
if (true) { // your check here
if($ionicHistory.currentStateName() != ‘app.home’){
$state.go(‘app.home’)
}else{
$ionicPopup.confirm({
title: ‘System Warning’,
template: ‘Are you sure you want to exit?’
}).then(function (res) {
if (res) {
ionic.Platform.exitApp();
}
})
}
}
}, 100);