0

react-native-router-flux v3.30.0 react-native v0.31.0

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

  componentWillUnmount() {
    BackAndroid.removeEventListener('hardwareBackPress',this.handleBackAndroid);
  }

  componentDidMount() {
    BackAndroid.addEventListener('hardwareBackPress',this.handleBackAndroid);
  }

  handleBackAndroid() {
    try {
      Actions.mainPage();
      return true;
    } catch (err) {
      if (onExitApp) {
        return onExitApp();
      }
    return false;
  }}

when i press BackAndroidButton then it's call handleBackAndroid function and app exit.

mavani
  • 1
  • in witch file are you registering for `hardwareBackPress ` event ? It should be the root js file (index.android.js) – LHIOUI Sep 15 '16 at 09:44

1 Answers1

0

Read the docs. It will exit the app unless one of your handlers returns true.

https://facebook.github.io/react-native/docs/backandroid.html

p3drosola
  • 5,784
  • 2
  • 23
  • 30