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 goes on an infinite loop while listening for changes with appState on android #30206
Comments
@codeamo I seem to be randomly stuck inside an app state loop - sometimes I'm stuck, sometimes I'm not - in release and debug react-native android builds. Curious, why did you close this ticket? |
@codeamo |
@shomatz not sure if it helps but for me it was because I was requesting app permissions on Android and every time AppState changed I requested them again. But I wasn’t aware that AppState changes to background while Android is requesting a permission (not the behaviour on iOS). Once I accounted for this, I fixed my infinite loop. |
@adam-ashored @shomatz sorry for the late response, but I have closed the issue because of no response. plus I haven't solved this issue yet as I quickly jumped to different tasks. I have reopened the issue so maybe it could be answered and it would help someone in the future. |
This seems to be happening in our case as well. We are using |
I'm facing the a similar issue as @info-bit I'm using react-native: "0.63.4" const _handleAppStateChange = (nextAppState) => {
// Running some code... later without stopping
};
useEffect(() => {
AppState.addEventListener('change', _handleAppStateChange);
return () => {
AppState.removeEventListener('change', _handleAppStateChange);
};
}, []); My solution was to use the |
@DracotMolver I'm not sure if it's okay to do this, I have a question unrelated to this issue, but related to your previous reply. Did you ever manage to get |
@intellimouseftw yes, but actually it was caused by another thing away from this. In my case was that I was handle a useEffect with an async callback. fixing that, everything worked perfect. So I changed it back to the onChange event |
const _handleAppStateChange = (nextAppState) => {
|
Thanks but I'm looking for a solution to the "focus" event, not the "change" event. The "change" event works fine. |
Okay sure |
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions. |
I have a similar problem, in my case, if I create apk in release mode, every time I open fresh app the state change to active, it's correct? because my perception of this state changes if it has a previous state, in my scenario I don't have previous state because it is a new open. Could someone help me on this? Thanks |
Our app (RN 0.66.0) is having similar problem, I don't know when it started happen, or what caused it, still investigating, but here is what I observed: |
@adam-ashored, can you explain how do you accounted "AppState changes to background while Android is requesting a permission (not the behaviour on iOS)."? |
@anastasia-iteric if your AppState is "close" to a permissions request eg. check for location permission everytime the app comes to the foreground via AppState then the underlying native request for permissions will put the app in the background for a fraction of a second and then bring it back to the foreground. As you can see, we get an infinite loop here. |
Experiencing this issue as well, +6 months later. When the app state is a dependency in a I'd really like to know fundamentally why the device is under the impression backgrounding is occurring, when no permissions model is popping up. It seems like a very common scenario to need to request permissions when foregrounding the app, I'm unsure how others are getting around this. In our case, creating a "has asked" flag isn't going to work. |
I fixed the problem with this source code below;
|
Issue still existed on "react-native": "0.71.8", |
I have a similar problem on "react-native": "0.72.4" + wix react-native-navigation 7.37 |
Had the same issue, as others have said, Android devices go to background when requesting permission.
The main problem for me was that I wasn't checking for this conditional Also I had to do await when calling requestPermissionAndExecute(passMethodToBeExecuted) inside handleAppStateChange method. That fixed it for me |
On Android, the To handle this, I created a package that implements the Android Lifecycle API for React Native: https://github.com/douglasjunior/react-native-applifecycle
|
Description
I have implemented AppState to listen for the app state and then do certain tasks when the app either goes foreground or background. Specifically, I am doing two actions on app state change.
The first option works pretty well, but when I added the dispatch action inside the handler to turn the flag on, the app state keeps changing again and again and the app state goes on an infinite loop.
React Native version:
Steps To Reproduce
Provide a detailed list of steps that reproduce the issue.
Expected Results
I expected the app to only change the state when opening the app, leaving the app, or transitioning between foreground & background which only works for IOS.
Snack, code example, screenshot, or link to a repository:
The text was updated successfully, but these errors were encountered: