React-native application does not shut down on back button

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 05:37:47

问题


My react-native application (on Android) does not shut down when back button is pressed. It closes and goes in the background and runs there (animates).

I also tried this, but got the same outcome:

BackHandler.addEventListener('hardwareBackPress', () => {

  console.log('back pressed');
  BackHandler.exitApp();
});

I want it to completely shut down when I press back or home button.

P.S. I'm using Expo for development and deployment, and also start the app through it.


回答1:


 constructor(props) {
                   super(props);
                   this.handleBackButtonClick = this.handleBackButtonClick.bind(this);
                 }

                 componentWillMount() {
                   BackHandler.addEventListener('hardwareBackPress', this.handleBackButtonClick);
                 }

                 componentWillUnmount() {
                   BackHandler.removeEventListener('hardwareBackPress', this.handleBackButtonClick);
                 }

                 handleBackButtonClick() {
                   BackHandler.exitApp();
                 }


来源:https://stackoverflow.com/questions/45191413/react-native-application-does-not-shut-down-on-back-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!