How do I exit/shut down a React Native app?

前端 未结 7 559
囚心锁ツ
囚心锁ツ 2020-12-13 04:10

If my React Native app fails to connect to its backend, I show an Alert with an OK button. If this happens, there\'s no point in the app continuing to run, so I\'d like to s

7条回答
  •  悲哀的现实
    2020-12-13 04:19

    This is how I've achieved it:

      componentWillMount() {
        BackHandler.addEventListener('hardwareBackPress', this.handleBackButtonClick);
      }
      componentWillUnmount() {
        BackHandler.removeEventListener('hardwareBackPress', this.handleBackButtonClick);
      }
      handleBackButtonClick() {
        BackHandler.exitApp();
        return true;
      }
    

提交回复
热议问题