ionic android返回键

每次点击返回键只会执行一个事件, 在自定义事件中要控制条件不满足时实行原默认动作. 如果只在一个view中监控, 还需要及时注销事件.

http://www.jianshu.com/p/b567cc657a49
http://blog.csdn.net/liangyiyiliang/article/details/53507411

// 返回键, view:100, 条件不满足再执行默认事件
$scope.homebackregister = $ionicPlatform.registerBackButtonAction(function(event) {
    function showConfirm() {
        var confirmPopup = $ionicPopup.confirm({
            title: '<strong>退出应用?</strong>',
            template: '你确定要退出吗?',
            okText: '退出',
            cancelText: '取消'
        });
        confirmPopup.then(function(res) {
            if (res) {
                ionic.Platform.exitApp();
            } else {
                $rootScope.backcount = 0;
            }
        });
    }

    if ($state.$current.name == 'home.index') {
        $rootScope.backcount = $rootScope.backcount || 0;
        $rootScope.backcount++;
        if ($rootScope.backcount == 2) {
            showConfirm();
        }
        event.preventDefault();
        return false;
    } else {
        navigator.app.backHistory();
    }
}, 101);

//只在当前view下注册, 退出即注销事件
$scope.$on('$destroy', $scope.homebackregister);
原文地址:https://www.cnblogs.com/wancy86/p/8046018.html