Android back button fixes, closes #454

This commit is contained in:
Adam Bradley
2014-01-30 22:01:20 -06:00
parent b20ce800ab
commit c3544d8a4a
5 changed files with 46 additions and 13 deletions

View File

@@ -1,8 +1,8 @@
angular.module('ionic.service.view', ['ui.router'])
.run( ['$rootScope', '$state', '$location', '$document', '$animate',
function( $rootScope, $state, $location, $document, $animate) {
.run( ['$rootScope', '$state', '$location', '$document', '$animate', '$ionicPlatform',
function( $rootScope, $state, $location, $document, $animate, $ionicPlatform) {
// init the variables that keep track of the view history
$rootScope.$viewHistory = {
@@ -49,6 +49,21 @@ angular.module('ionic.service.view', ['ui.router'])
}
});
// Triggered when devices with a hardware back button (Android) is clicked by the user
// This is a Cordova/Phonegap platform specifc method
function onHardwareBackButton(e) {
if($rootScope.$viewHistory.backView) {
// there is a back view, go to it
$rootScope.$viewHistory.backView.go();
} else {
// there is no back view, so close the app instead
navigator.app.exitApp();
}
e.preventDefault();
return false;
}
$ionicPlatform.onHardwareBackButton(onHardwareBackButton);
}])
.factory('$ionicViewService', ['$rootScope', '$state', '$location', '$window', '$injector',