-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
App state does not show state going from 'background' to 'active' #29218
Comments
@cHaLkdusT I'm currently using react-native 0.63.2 and react 16.13.1. I'm still having this problem on iOS. When leaving the app state goes to 'background', but then in logs I can see that it changes to 'active', even though I have not returned to the app. Thus, when I come back to the app, current and next state are both 'active', which prevents me from detecting that user opened app again from the background. |
Verified your repro in the Snack. It shows going to background the first time... but then doesn't any time after that. It just gets stuck as 'active'. Was that also what you were seeing? |
If I remember correctly, Snack with class component implementation provided in the official React Native documentation works as intended. |
I was experiencing this issue as well. I fixed it by using a ref instead of state for the appState. I found that it's actually the way described in the documentation (https://reactnative.dev/docs/appstate)
|
Thanks. I did not notice it before. It seems that it was updated in this commit: |
Hey @jaworek, I've attached the link 4 months ago. It seems like you didn't check the link for the new code snippet reference. 😁 |
@cHaLkdusT From what I see, this commit with updated documentation was made over a week after I you posted a link to the same documentation page that I did in my first comment. Previously it had the same buggy implementation as I provide in the snack and code example. I'm glad that it was fixed :D |
|
Description
I'm trying to use
AppState
to detect if app is going from 'background' to 'active'In docs it appears that it should be easily detectable:
https://reactnative.dev/docs/appstate
When trying it in my app it never runs console.log in the if statement that checks state going from 'background' to 'active'
In logs there is only 'active' -> 'background' and when going back to app it log 'active' -> 'active'.
React Native version:
react-native: 0.62.2
It does not work on web previews, as well as on android devices.
System:
OS: Windows 10 10.0.18362
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Memory: 3.56 GB / 15.89 GB
Binaries:
Node: 12.18.0 - C:\Program Files\nodejs\node.EXE
Yarn: Not Found
npm: 6.14.4 - C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: Version 3.0.0.0 AI-171.4443003
Languages:
Java: Not Found
Python: Not Found
npmPackages:
@react-native-community/cli: Not Found
react: 16.11.0 => 16.11.0
react-native: 0.62.2 => 0.62.2
npmGlobalPackages:
react-native: Not Found
Steps To Reproduce
Provide a detailed list of steps that reproduce the issue.
Expected Results
I expect to see AppState to show that app is going 'active' -> 'background', when leaving app, and 'background' -> 'active', when going back.
Snack, code example, screenshot, or link to a repository:
https://snack.expo.io/MOOwV9_Nh8
The text was updated successfully, but these errors were encountered: