BackHandler

Inherits BackHandler.

Properties

Property Supported Supported on Roku Dynamic on Roku Notes
exitApp Partial ~x Not Possible Android and Tizen only
addEventListener ~v ~v N/A  
removeEventListener ~v ~v N/A  

Notes:

  • On tvOS, the application closes when the Siri remote Menu button is pressed and there are no registered event listeners for the BackHandler. Conversely, on all other platforms, your app needs to handle the back button press and exit the application.
  • For components where you want your application to exit when the back button is pressed use the code sample below to only register a BackHandler listener if the application isn’t running on tvOS.
  • For all other application components, register a listener to handle the event as needed (even on tvOS) and be sure to remove the listener when the component unmounts.

See the following code sample for more details:

componentDidMount() {
  if(!isTVOS){
    BackHandler.addEventListener("hardwareBackPress", this.handleBackButtonPressed);
  }
}

componentWillUnmount() {
  if(!isTVOS){
    BackHandler.removeEventListener("hardwareBackPress", this.handleBackButtonPressed);
  }
}

handleBackButtonPressed = () => {
  BackHandler.exitApp(); // Where supported
  return true;
}