1.在componentWillMount

 componentWillMount() {
        this.backHandler && this.backHandler.remove();
    }

2.在componentDidMount

componentDidMount() {
    this.backHandler = BackHandler.addEventListener('hardwareBackPress',
        this.onBackButtonPressAndroid);
}

3.退出函数

  onBackButtonPressAndroid = () => {
        if (this.props.navigation.isFocused()) {
            if (this.lastBackPressed && this.lastBackPressed + 2000 >= Date.now()) {
                //最近2秒内按过back键,可以退出应用。
                return false;
            }
            this.lastBackPressed = Date.now();
            NRJCore.toast("再按一次退出");
            return true;
        }

    }
Last modification:November 26, 2018
If you think my article is useful to you, please feel free to appreciate