I want to save my last visited screen by the user in Async Storage before the user exits the application. As there is no lifecycle event in react-native to look for an app being closed, I want to trigger a function in react-native when OnDestroy event occurs in android.
Asked
Active
Viewed 874 times
0
-
Possible duplicate of [How to detect when a React Native app is closed (not suspended)?](https://stackoverflow.com/questions/38962034/how-to-detect-when-a-react-native-app-is-closed-not-suspended) – FreakyCoder Nov 15 '19 at 08:16
1 Answers
0
Wouldn't it be easier to write the log when a screen is shown?
Just overwrite the value every time you open a new screen and when the user closes the app, the stored entry will be the last screen the user visited.
Not really familiar with React but in Android you can't assume that onDestroy will be called for an Activity. From the documentation of onDestroy
:
Note: do not count on this method being called as a place for saving data!
https://developer.android.com/reference/android/app/Activity.html#onDestroy()

patrick.elmquist
- 2,113
- 2
- 21
- 35