React-native componentWillUnmount not called

I work on Android, and if I use the hardware return button to exit the application, the componentWillUnmount function is called. However, if I use the square button to show a list of running applications and swipe the screen to close this function, the call will not be called.

Any ideas on how to determine when the application is closing so I can clear timers, save data, etc.

Thank.

+5
source share
3 answers

You can check AppState Api for information about detecting the current state of the foreground or active. https://facebook.imtqy.com/react-native/docs/appstate.html

+2
source

I ran into the same problem. To solve this problem, I did not add an event listener to stateChange. Instead, I just look at AppState.currentState inside the componentDidMount () function.

The problem was that eventListeners connected when the component was mounted but not disconnected in the WillUnmount component.

0
source

, , , (, React Native Router Flux) Actions.currentScene === 'Home' - , .

0
source

Source: https://habr.com/ru/post/1663990/


All Articles