Skip to content

[Android 0.37] AppState.currentState incorrectly returns "active" when app is launched in background #11561

@vikeri

Description

@vikeri

Description

When the app is started in the background (Headless JS) from for example a JobScheduler the AppState.currentState is initially "active" even though it should return "background". When called later on it gives "uninitialized" which is not documented.

This probably stems from AppState not taking into account how HeadlessJS is run.

The default value defined here is what is causing this issue since this callback is not called before one tries to access the currentState property.

Reproduction

  1. Fork the example folder of react-native-background-job : https://github.com/vikeri/react-native-background-job/tree/master/example
  2. Log AppState.currentState in the beginning of the index.android.js file.
  3. Schedule the job
  4. Kill the app
  5. Watch the job run and see the output of AppState.currentState

Solution

A solution could be to deprecate currentState and expose the getCurrentState method as suggested here and here.

Additional Information

  • React Native version: 0.37
  • Platform: Android
  • Operating System: MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions