Skip to content

Conversation

@RubyFeinstein
Copy link

@RubyFeinstein RubyFeinstein commented May 5, 2025

Issue

During app startup, react-native's AppState.currentState can incorrectly report background when the app is actually in the foreground. This happens because:

  1. AppStateModule relies on onHostResume and onHostPause event subscriptions to track state
  2. The initial state can incorrectly initialize to APP_STATE_BACKGROUND when reactContext.lifecycleState === LifecycleState.BEFORE_CREATE (which occurs before root view attachment)

Solution

This PR adds an isAppForegroundedByMemoryState() method that provides a more accurate initial state detection when the React context is in BEFORE_CREATE lifecycle state.

Future Improvements

While this is a quick workaround to address the immediate issue, potential future improvements:

  1. Leveraging Android activity lifecycle to set initial state to RESUMED on onCreate
  2. Mapping LifecycleState.BEFORE_CREATE to unknown instead of incorrectly mapping to background

@RubyFeinstein RubyFeinstein force-pushed the pasten/0.78.0_app_state_fix branch from c8dfa58 to 8f51409 Compare May 5, 2025 21:48
@RubyFeinstein RubyFeinstein marked this pull request as ready for review May 5, 2025 22:06
@RubyFeinstein RubyFeinstein merged commit e55261b into 0.78.0-discord May 5, 2025
26 of 30 checks passed
RubyFeinstein added a commit that referenced this pull request May 5, 2025
## Issue
During app startup, react-native's `AppState.currentState` can incorrectly report `background` when the app is actually in the foreground. This happens because:

1. `AppStateModule` relies on `onHostResume` and `onHostPause` event subscriptions to track state
2. The initial state can incorrectly initialize to `APP_STATE_BACKGROUND` when `reactContext.lifecycleState === LifecycleState.BEFORE_CREATE` (which occurs before root view attachment)

## Solution
This PR adds an `isAppForegroundedByMemoryState()` method that provides a more accurate initial state detection when the React context is in `BEFORE_CREATE` lifecycle state.

## Future Improvements
While this is a quick workaround to address the immediate issue, potential future improvements:
1. Leveraging Android activity lifecycle to set initial state to `RESUMED` on `onCreate`
2. Mapping `LifecycleState.BEFORE_CREATE` to `unknown` instead of incorrectly mapping to `background`
bdbaraban pushed a commit that referenced this pull request May 22, 2025
## Issue
During app startup, react-native's `AppState.currentState` can incorrectly report `background` when the app is actually in the foreground. This happens because:

1. `AppStateModule` relies on `onHostResume` and `onHostPause` event subscriptions to track state
2. The initial state can incorrectly initialize to `APP_STATE_BACKGROUND` when `reactContext.lifecycleState === LifecycleState.BEFORE_CREATE` (which occurs before root view attachment)

## Solution
This PR adds an `isAppForegroundedByMemoryState()` method that provides a more accurate initial state detection when the React context is in `BEFORE_CREATE` lifecycle state.

## Future Improvements
While this is a quick workaround to address the immediate issue, potential future improvements:
1. Leveraging Android activity lifecycle to set initial state to `RESUMED` on `onCreate`
2. Mapping `LifecycleState.BEFORE_CREATE` to `unknown` instead of incorrectly mapping to `background`
Flewp pushed a commit that referenced this pull request Aug 25, 2025
## Issue
During app startup, react-native's `AppState.currentState` can incorrectly report `background` when the app is actually in the foreground. This happens because:

1. `AppStateModule` relies on `onHostResume` and `onHostPause` event subscriptions to track state
2. The initial state can incorrectly initialize to `APP_STATE_BACKGROUND` when `reactContext.lifecycleState === LifecycleState.BEFORE_CREATE` (which occurs before root view attachment)

## Solution
This PR adds an `isAppForegroundedByMemoryState()` method that provides a more accurate initial state detection when the React context is in `BEFORE_CREATE` lifecycle state.

## Future Improvements
While this is a quick workaround to address the immediate issue, potential future improvements:
1. Leveraging Android activity lifecycle to set initial state to `RESUMED` on `onCreate`
2. Mapping `LifecycleState.BEFORE_CREATE` to `unknown` instead of incorrectly mapping to `background`
Flewp pushed a commit that referenced this pull request Oct 8, 2025
## Issue
During app startup, react-native's `AppState.currentState` can incorrectly report `background` when the app is actually in the foreground. This happens because:

1. `AppStateModule` relies on `onHostResume` and `onHostPause` event subscriptions to track state
2. The initial state can incorrectly initialize to `APP_STATE_BACKGROUND` when `reactContext.lifecycleState === LifecycleState.BEFORE_CREATE` (which occurs before root view attachment)

## Solution
This PR adds an `isAppForegroundedByMemoryState()` method that provides a more accurate initial state detection when the React context is in `BEFORE_CREATE` lifecycle state.

## Future Improvements
While this is a quick workaround to address the immediate issue, potential future improvements:
1. Leveraging Android activity lifecycle to set initial state to `RESUMED` on `onCreate`
2. Mapping `LifecycleState.BEFORE_CREATE` to `unknown` instead of incorrectly mapping to `background`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants