react-native icon indicating copy to clipboard operation
react-native copied to clipboard

When an intent is received by the app, AppState receive a background state then an active state just after

Open gritwyplay opened this issue 3 years ago • 7 comments
trafficstars

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

  1. Start the demo app (https://github.com/gritwyplay/ExempleAppState)
  2. Send an intent ( adb shell am start -a "android.intent.action.VIEW" -d test://test)
  3. Observe current app state in the app ("Current state is: xxxxxx")

Expected

  1. The App start
  2. The intent is fired
  3. The current state stay active

Actual

  1. As Expected
  2. As Expected
  3. 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

gritwyplay avatar Sep 06 '22 08:09 gritwyplay

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

mkizesov avatar Sep 17 '22 15:09 mkizesov

I have the same issue in Android ass well (RN 0.66.5). The app switches back and forth between "background" and "active" state.

thecookieorg avatar Nov 18 '22 16:11 thecookieorg

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

PrimulaX avatar Mar 31 '23 14:03 PrimulaX

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.

github-actions[bot] avatar Sep 28 '23 05:09 github-actions[bot]

No stale plz.

PrimulaX avatar Sep 28 '23 06:09 PrimulaX

As of today, this is still happening. anyone of found a work around?

Skullcan avatar Mar 20 '24 18:03 Skullcan

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 background state signifies that the entire app is in the background.
  • On Android, the background state 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 state background will be dispatched only when the entire app is in background.

douglasjunior avatar May 03 '24 11:05 douglasjunior