I am building an Android application by cordova. I use React & Redux in my application. I want to detect when the app is open. I add that logic in the componentDidMount
method of my root component. But it only works when my app is open for that first time. It doesn't work in the case that I switch to other app and switch back to my app. I think this is because my app is still running in the background. So the componentDidMount
method is not called in this case. Is there a way to detect that?
Asked
Active
Viewed 1,246 times
0

Joey Yi Zhao
- 37,514
- 71
- 268
- 523
-
that's alike trying to detect if a web-browser window is minimized or has a screensaver running from within sand-boxed JavaScript. you'd need to use a plugin to obtain the state: – Martin Zeitler Oct 31 '18 at 04:48
-
Possible duplicate of [check android application is in foreground or not?](https://stackoverflow.com/questions/8489993/check-android-application-is-in-foreground-or-not) – Martin Zeitler Oct 31 '18 at 04:48
-
let us know if this is Cordova application or React Native app, so there are different plugins and methods in the Cordova and react native apps to detect this. – Kirankumar Dafda Oct 31 '18 at 04:53
1 Answers
1
If you are creating application using Cordova
Here you can check the pause and resume events for checking app is in foreground or background https://cordova.apache.org/docs/en/latest/cordova/events/events.html
For React native app
AppState will help you to detect the state : https://facebook.github.io/react-native/docs/appstate

Kirankumar Dafda
- 2,354
- 5
- 29
- 56