Registerbackbuttonaction not able to redirect to the page specified inside call back

I am handling back operation from a screen in two places one at the top left corner (back Icon) which is working fine(calls goBack) and another on hardware back button in Android with ionic’s registerbackbuttonAction callback (not working fine).When I am putting an alert inside callback it is showing, however, the redirection to specified path is not happening.Instead, app exits?.

Note: (I have used this callback with different functions in some other controllers in other places for showing a popup and exiting app which are working fine,all with priority 1000) .


$scope.goBack = function() {

            $localStorage.PapersObj = [];
            //window.history.back();
            var subjectId = $localStorage.pathTrace.subjectId;
            var subjectName = $localStorage.pathTrace.subName;
            var subTopic = $localStorage.pathTrace.subTopicId;

            if(subTopic===undefined){
                $location.path("/topics_pr/" + subjectId + "/" + subjectName);
            }

        };

        var deReg = $ionicPlatform.registerBackButtonAction(function(event) {
            //event.preventDefault();
            //alert("iam called");
            var subjectId = $localStorage.pathTrace.subjectId;
            var subjectName = $localStorage.pathTrace.subName;
            var subTopic = $localStorage.pathTrace.subTopicId;

            //if(subTopic===undefined){
                $location.path("/topics_pr/" + subjectId + "/" + subjectName);
            //}

        },1000,"papers"+topicId);

@abrj
use this

$ionicPlatform.registerBackButtonAction(function (event) {

function confirmExit() {
$ionicPopup.confirm({
title: ‘Exit App’,
template: ‘Are you sure you want to exit?’
}).then(function(res){
if( res ){
ionic.Platform.exitApp();
}
});
}

if($state.is('app.home')){
  confirmExit();

}
else{

   $ionicHistory.goBack();
    
}

}, 100);

Thanks for the reply! As I had mentioned, I am able to do the above functionality but problem arises only when I try to perform navigation directly without showing a popup, unable to make the back operation work in that case…