Back Handler not working

#1

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;
  }
#2

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
#3

Thats fair.

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

#4

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

Specifically the last section regarding React Lifecycles.

#5

@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

closed #6

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