这是我尝试过的。我不知道现在该怎么办。如果可以的话,我会很高兴
componentDidMount(){
AppState.addEventListener('change',() => this.handleAppStateChange)
}
componentWillUnmount(){
AppState.removeEventListener('change',() => this.handleAppStateChange)
}
handleAppStateChange = (nextAppState) => {
if(this.state.lastAppState === 'active' && nextAppState === 'inactive'){
addIncome().then().catch(error => {})
}
this.setState({lastAppState: nextAppState})
}