Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
vikeri opened this issue Dec 20, 2016 · 6 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@vikeri
Copy link
Contributor

vikeri commented Dec 20, 2016

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
@tnortman
Copy link

Ditto, happens on 0.39.2 as well.

@JonoH
Copy link

JonoH commented Feb 24, 2017

Same issue my side.

@JulioOrellana
Copy link

JulioOrellana commented Jul 20, 2017

So, by React Native's side there is not way to bypass this? The only solution is to add some native code directly to Android code. So bad. AppState works correctly on iOS.

@hramos hramos added the Icebox label Sep 21, 2017
@hramos
Copy link
Contributor

hramos commented Sep 21, 2017

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

@hramos hramos closed this as completed Sep 21, 2017
@olegdater
Copy link

can't believe this is still an issue :(

RN 0.53.3
Android 8

@stevenpal
Copy link

Noticed that this is still an issue as well on RN 0.55.4. The AppState.currentState always seems to return active no matter what state the app is in on Android. Although AppState.currentState isn't updated, the event listeners do seem to be working. So a workaround is to track the state yourself as they do in the example code using an event listener: https://facebook.github.io/react-native/docs/appstate.html. Seems to be working so far for me.

@facebook facebook locked as resolved and limited conversation to collaborators Sep 21, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Sep 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

9 participants