2

Let's say I'm inside a BroadcastReceiver class that handles push notification.

How can I check if the application, this service is running for, is in the Foreground, in the Background or is completely turned off?

Humberd
  • 2,794
  • 3
  • 20
  • 37
  • You can check this https://developer.android.com/reference/android/app/Application.ActivityLifecycleCallbacks.html but not entirely sure if it meets your requirement https://stackoverflow.com/questions/10606408/automatically-log-android-lifecycle-events-using-activitylifecyclecallbacks – Sunil Sunny Mar 07 '18 at 13:14

1 Answers1

0

You can just call AppState API from react-native core (https://facebook.github.io/react-native/docs/appstate.html) and get this information.

If you are using react-native-push-notification module, when you receive a notification, you also receive a boolean that indicates if the app is on foreground mode or not.

https://github.com/zo0r/react-native-push-notification

Rafael Motta
  • 2,328
  • 2
  • 19
  • 18