Problems with the return button in native ionic

I have a problem with the back button from the Android, my project is returning only once in the history of the application. I am using the ionic version 1.0.0-beta.14. My Code is the following:

angular.module('ionic')
  .run(function($ionicPlatform,$ionicPopup, $state,$ionicHistory){
    $ionicPlatform.registerBackButtonAction(function (event) {
      //console.log(window.history);
      if($state.current.name=="app.listar_CELULAS"){
        alert("entro aqui");
        navigator.app.exitApp();
      }
      else {
        //window.history.back();
      }
    }, 100);
});

I am also with the following problem, when in pagina home, instead of returning in the historia i need him to quit the application. I am trying to and looking for this in several places, and up to the present moment nobody has managed to assist me in this. I am rookie with ionic and i would be grateful for a help. Thank You`