Is there an event to listen on for when a React Native app is quit?

Viewed 433

Im interested in firing a function when a user quits the app, meaning they bring up multi-tasking and close-out the app.

I'm not talking about navigating back to your home screen and keeping the app in the background.

I'm aware of AppState, but as I said, im looking for the suit scenario, not a change from active, to the background

Is this possible, my componentWillUnmount() is not firing in this case?

1 Answers

Here is an example using an OS background task and additional library. That might be your best bet without using AppState/ComponentDidUnmount() which would only detect active/background status:

https://github.com/billmalarky/react-native-queue#os-background-task-full-example

componentWillUnmount() won't fire because that's only when a component is being removed from the DOM.

The JavaScript engine closes when the app does so there's no other way to communicate with it once the app is closed.

Related