问题
My react-native application (on Android) does not shut down when back button is pressed. It closes and goes in the background and runs there (animates).
I also tried this, but got the same outcome:
BackHandler.addEventListener('hardwareBackPress', () => {
console.log('back pressed');
BackHandler.exitApp();
});
I want it to completely shut down when I press back or home button.
P.S. I'm using Expo for development and deployment, and also start the app through it.
回答1:
constructor(props) {
super(props);
this.handleBackButtonClick = this.handleBackButtonClick.bind(this);
}
componentWillMount() {
BackHandler.addEventListener('hardwareBackPress', this.handleBackButtonClick);
}
componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButtonClick);
}
handleBackButtonClick() {
BackHandler.exitApp();
}
来源:https://stackoverflow.com/questions/45191413/react-native-application-does-not-shut-down-on-back-button