react-native
react-native copied to clipboard
When an intent is received by the app, AppState receive a background state then an active state just after
Description
When the app receive an Intent the AppState quickly change to background before come back to active instead of staying in "active" state.
Relevant sources in react native:
- https://github.com/facebook/react-native/blob/8bd3edec88148d0ab1f225d2119435681fbbba33/ReactAndroid/src/main/java/com/facebook/react/modules/appstate/AppStateModule.java#L65-L81
- https://github.com/facebook/react-native/blob/8bd3edec88148d0ab1f225d2119435681fbbba33/ReactAndroid/src/main/java/com/facebook/react/bridge/LifecycleEventListener.java#L32-L49
- https://github.com/facebook/react-native/blob/8bd3edec88148d0ab1f225d2119435681fbbba33/ReactAndroid/src/test/java/com/facebook/react/modules/timing/TimingModuleTest.java
Version
0.70
Output of npx react-native info
info Fetching system and libraries information...
System:
OS: Linux 5.19 Arch Linux
CPU: (6) x64 Intel(R) Core(TM) i5-8500 CPU @ 3.00GHz
Memory: 10.91 GB / 15.43 GB
Shell: 5.9 - /usr/bin/zsh
Binaries:
Node: 18.8.0 - /usr/bin/node
Yarn: 1.22.19 - /usr/bin/yarn
npm: 8.19.1 - /usr/bin/npm
Watchman: Not Found
SDKs:
Android SDK:
API Levels: 30, 31, 33
Build Tools: 29.0.0, 29.0.2, 30.0.3, 31.0.0, 33.0.0
System Images: android-30 | Android TV Intel x86 Atom, android-30 | Intel x86 Atom_64, android-30 | Google TV Intel x86 Atom
Android NDK: 25.1.8937393
IDEs:
Android Studio: AI-212.5712.43.2112.8815526
Languages:
Java: 1.8.0_345 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.1.0 => 18.1.0
react-native: 0.70.0 => 0.70.0
npmGlobalPackages:
*react-native*: Not Found
Steps to reproduce
Steps
- Start the demo app (https://github.com/gritwyplay/ExempleAppState)
- Send an intent (
adb shell am start -a "android.intent.action.VIEW" -d test://test) - Observe current app state in the app ("Current state is: xxxxxx")
Expected
- The App start
- The intent is fired
- The current state stay active
Actual
- As Expected
- As Expected
- The current state quickly change to "background" before come back to "active"
Snack, code example, screenshot, or link to a repository
Demo app : https://github.com/gritwyplay/ExempleAppState
Have the same issue in Android (real device), the app is switching a couple of times back to "background" and "active" state (in ios it works correctly), react-native v. 0.67.4
I have the same issue in Android ass well (RN 0.66.5). The app switches back and forth between "background" and "active" state.
Same issue, I'm trying to blur the app in App Switcher it works on IOS, but on android, the state became active immediately after background state
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
No stale plz.
As of today, this is still happening. anyone of found a work around?
On Android, the background state means that the React Native Activity is in background, and not necessary the entire app.
To handle this, I created a package that implements the Android Lifecycle API for React Native: https://github.com/douglasjunior/react-native-applifecycle
Why Use This?
The original AppState API provided by React Native behaves differently between Android and iOS, particularly regarding the background state:
- On iOS, the
backgroundstate signifies that the entire app is in the background.- On Android, the
backgroundstate indicates that the React Native Activity is in the background, which might not necessarily mean the entire app is in the background.By using
react-native-applifecycle, you can handle these differences seamlessly across both platforms, ensuring that the statebackgroundwill be dispatched only when the entire app is in background.