Back Handler not working

I’m having trouble implementing Back handler in my expo project. Any reason why its not working?

  componentDidMount()
  {
    BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
  }

  componentWillUnmount() 
  {
      BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress);
  }

  handleBackPress = async () => {
      this.props.navigation.goBack()
      return true;
  }
1 Like

Hey @productivenyc,

Can you elaborate on what you mean by “its not working”? Always hard to help out without more information.

Cheers,

Adam

1 Like

Thats fair.

It doesn’t call the function. Also not sure why I had it async but it doesn’t work either way.

Gotcha. This page may be of use to: Redirecting to https://reactnavigation.org/docs/custom-android-back-button-handling

Specifically the last section regarding React Lifecycles.

@adamjnav

Im pretty sure I tried moving the addListener into the constructor. No change. But ill try again.

BTW I’m using react navigation so I’m pretty sure I copied that example actually

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.