react-native Android - Hardware Back Button Example of Hardware back button detection using BackHandler


Example

Since BackAndroid is deprecated. Use BackHandler instead of BackAndroid.

import { BackHandler } from 'react-native';

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