Example of Hardware back button detection using BackHandler

suggest change

BackAndroid is deprecated. Use BackHandler instead.

The listener has to be a method React will call, so the name is componentWillMount, not ComponentWillMount. Register it from the component so this is that component. onMainScreen and goBack are yours to implement. Return true when you have handled the press.

import { BackHandler } from 'react-native';

componentWillMount() {
  BackHandler.addEventListener('hardwareBackPress', () => {
    if (!this.onMainScreen()) {
      this.goBack();
      return true;
    }
    return false;
  });
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents