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

AppState.addEventListener stop working after staying in background for too long #22540

Closed
3 tasks done
James2516 opened this issue Dec 6, 2018 · 3 comments
Closed
3 tasks done
Labels
API: AppState Bug Resolution: Locked This issue was locked by the bot.

Comments

@James2516
Copy link

James2516 commented Dec 6, 2018

Environment

  React Native Environment Info:
    System:
      OS: macOS 10.12.6
      CPU: x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
      Memory: 282.63 MB / 16.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 8.12.0 - /usr/local/bin/node
      Yarn: 1.12.3 - /usr/local/bin/yarn
      npm: 6.4.1 - /usr/local/bin/npm
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.12, tvOS 12.1, watchOS 5.1
    IDEs:
      Android Studio: 3.1 AI-173.4819257
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.5.0 => 16.5.0 
      react-native: 0.57.1 => 0.57.1 

Description

AppState.addEventListener('change', this._handleAppStateChange)

I called this in a js file on global scope. It works fine initially but if the app stays in the background for too long, it will stop working even after the app resumes (not restarts, app was still in the background).

Tested on Samsung Android 8.0.

@react-native-bot
Copy link
Collaborator

It looks like you are using an older version of React Native. Please update to the latest release, v0.57 and verify if the issue still exists.

The "⏪Old Version" label will be removed automatically once you edit your original post with the results of running react-native info on a project using the latest release.

@rickhanlonii
Copy link
Member

Hey @James2516, sorry for the delay here

This API is not supported globally, it needs to be inside a react component to make sure the app lifecycle is managed correctly, see the docs here: https://facebook.github.io/react-native/docs/appstate

@James2516
Copy link
Author

James2516 commented Mar 19, 2019

Hi @rickhanlonii, thanks for the clarification.
It is not stated on the docs that the API call should be inside a React component. You might want to add that to the docs?

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

No branches or pull requests

4 participants