title: Back Button React native exit app
body: <p>I have put android back button exit the app functionality  in my react native app in my home screen. But when I press android back button on other screens then also it is getting called.</p>
  
  <pre><code>componentDidMount() {
  
      if (Platform.OS == "android") {
          BackHandler.addEventListener('hardwareBackPress', this.handleBackButton);                           
    }
      this._setupGoogleSignin();           
      this._getUserDetails();
      const { navigate } = this.props.navigation;
      console.log("object url is", this.state.postsArray[0].url);
  
  }
  
  handleBackButton = () =&gt; {               
      Alert.alert(
          'Exit App',
          'Exiting the application?', [{
              text: 'Cancel',
              onPress: () =&gt; console.log('Cancel Pressed'),
              style: 'cancel'
          }, {
              text: 'OK',
              onPress: () =&gt; BackHandler.exitApp()
          }, ], {
              cancelable: false
          }
       )
       return true;
     }
  componentWillUnmount() {
      BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton);
    }
  </code></pre>