react-native-router-flux v3.30.0 react-native v0.31.0
constructor(props){
super(props);
this.handleBackAndroid = this.handleBackAndroid.bind(this);
}
componentWillUnmount() {
BackAndroid.removeEventListener('hardwareBackPress',this.handleBackAndroid);
}
componentDidMount() {
BackAndroid.addEventListener('hardwareBackPress',this.handleBackAndroid);
}
handleBackAndroid() {
try {
Actions.mainPage();
return true;
} catch (err) {
if (onExitApp) {
return onExitApp();
}
return false;
}}
当我按下 BackAndroidButton 时,它会调用 handleBackAndroid 函数并退出应用程序。