Back button in android devices

Hi,

I have a problem with registerBackButtonAction in my app,

i have slide menu and tabs for example my state is : menu.tabs.home ,
menu.tabs.favorite

and i have som page without menu and tab for example my states is : aboutUs ,
setting, setting.language

i call my code about back button in .run in app.js

my problem is:

in tabs back button works fine and without bug but when i change state to for
example aboutUs or setting.language back button some time works fine and some
time not work !!!

i am so confused:( can you help me? where is my mistake?

my codes in run for back button is:

myApp.run(function($ionicPlatform, $state) {
  $ionicPlatform.ready(function() {
      $ionicPlatform.registerBackButtonAction(function (event) {
        if($state.current.name=="menu.tabs.home"){
          alert("1");
          navigator.app.exitApp();
        }
        else {
          alert("2");
          navigator.app.backHistory();
        }
      }, 100);
    });
});

Thank you.

because you are using the native back functionality… so you working with the browser history and not the ionic viewHistory.
Use
$ionicHistory.goBack() instead of navigator.app.backHistory();

@bengtler no even alert not work
when i am not in tabs states ,some time back button event not fire and some time fire :

  $ionicPlatform.registerBackButtonAction(function (event) {
     alert( " this is not fire some times " )
  }, 100);

the priority 100 overwrites only the handling for ordinary statechanges as in tabs.

for popups, modals, popover, actionsheets you need to set a higher priority