-
Notifications
You must be signed in to change notification settings - Fork 16
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
When the app comes back to the foreground from the background #504
Comments
When I move the flutter app to the background and come back after about 15 minutes, I am logged as 80003 error. Connection temporarily unavailable code= 80003 |
Hey @walkerJung, Thank you for choosing Ably! You don't need to explicitly reconnect after your app comes back from the background, but you need to check the resumed flag on the channel's attached event. When resumed is false, some messages may have been lost while the app was in the background, and you probably need to handle this in your business logic (e.g., refetch data from the backend). Here is the quote from our FAQ docs about connection recovery:
|
@ttypic Thank you for your answer, but the status of my realtime provider is not changing from disconnected to connected and all the connections are still disconnected. |
On my app, I'm using it by declaring it as a provider to create only one realtime object because they're subscribing to different channels on different screens, is this part wrong? |
@walkerJung, it doesn't look like you're doing anything wrong. Can you share some details that can help us understand better:
|
@ttypic Thank you for your answer, platform : IOS, Android
The above source code is my realtime object My app has multiple channels, or chat screens, so I made this to create and write only one realtime object. When I send the app to the background on the screen where the entire user can gather and chat, and after a certain period of time, the realtime.connection.state does not change from disconnected to connected. |
It seems to mainly happen on Android devices. After leaving the Android app in the background for more than 30 minutes to an hour, when I move to the foreground, the realtime connection seems to be disconnected and I don't try to reconnect |
https://faqs.ably.com/error-code-80003 Fifteen seconds later, it's still disconnected |
This is my source code, but it doesn't happen on ios, but on android the app doesn't connect ably when it comes back to foreground after about 5 hours in the background. I think it only happens on android, is there anyone similar to me? |
@walkerJung thank you very much for the details. We are looking into this. Right now, we still have difficulties reproducing the issue. Could you also share the Android version that you are using? We'll keep you posted as soon as we find something |
@ttypic Thank you so much for answering, my test android phone's Android version is 13 |
Should I deliver the id value (realtime.connection.id ) of the realtime object to the recoverKey value? There were times when Error code : 80008 was shown. Maybe it's because the new connection is connected, but my app still refers to the last connection? |
Hi @walkerJung you don't need to set |
hi @sacOO7 Thank you for your answer, then I don't need this part in my source code?
|
Yes, you don't need to do it as such! |
@sacOO7 |
Yeah, I am familiar with a concept of providers in android. I can give you few suggestions on this. You should check for
|
You can also check official doc. on state management https://docs.flutter.dev/data-and-backend/state-mgmt/simple |
I feel problem with using |
I think your advice will be very helpful. I will refer to the linked content carefully and modify the realtime object I made as a provider. Thank you very much! @sacOO7 |
I changed the realtime object from provider to global variable and it seems the same thing happens on Android |
|
|
Can you check if you can initialize |
I'm not using a provider right now,
Create a realtime object by calling initializeGlobalRealtime() within the main method
I'm using it like this where I need realtime |
You can check the documentation -> https://ably.com/docs/connect/states?lang=java |
As a part of new flutter release, we will have a method called |
So that method is not available now? |
I make and use one realtime on the source code, but I don't understand that the app is disconnected when it goes to the background only on Android and then comes back to the foreground after a certain amount of time. My app doesn't need to be connected even in the background. When the app returns to the foreground, there is also a logic to add observer to bring back data, so for me, only about connection needs to be connected and operated normally, but I don't know why that part isn't working |
|
Interesting, you might like to take a look at https://developer.android.com/training/monitoring-device-state/doze-standby#understand_doze. |
You might like to test your app in doze mode https://developer.android.com/training/monitoring-device-state/doze-standby#assessing_your_app. It will be helpful if we can reproduce the issue. |
Is this a bug that only happens to me? |
Not sure, it seems @ttypic is not able to reproduce the same from his side. Maybe, it has do with the way |
I have now changed the source code to disable the riversepod provider, but the same thing is still happening |
Hey, can you do one thing? Upload this buggy flutter source code as a example github repo. I can clone and will try to reproduce the same from my side. Also are you using emulator for this ? |
I'm testing with an actual Android device, you're saying I need a full source code that I can build right away? |
Yes, are you able to reproduce the same on android emulator? |
Thanks to your help, I think using provider was a big problem. Apart from this, I have another question, and I wonder why the above source doesn't work. When the app goes to the background and comes back, it shows loader if it's not connected, and when it's connected, it clears loader, but the loader keeps showing up even after it's actually connected
|
@walkerJung is your issue resolved ( apart from loader issue ) ? What did you do differently to implement the same ?
https://api.flutter.dev/flutter/widgets/State/setState.html |
The part surrounding the realtime with a provider was simply transformed into a single tone class and used. How many seconds do you usually set the values of disconnected RetryTimeout, suspendedRetryTimeout, fallbackRetryTimeout, and channelRetryTimeout? Is it okay to set it to 3000ms? |
You can set it according to your requirement. But, default values from |
Are there any problems when you set it shorter than 3 seconds or 3 seconds? |
Yes, you can set and test the same. Btw, |
Yes, it's working normally. Your help is really good. I think the problem was with using the provider |
@sacOO7 Now I'm going to close this issue. It was my mistake using provider and thank you for your care. |
Btw, @walkerJung if needed, you can post updated code here, so it's helpful for others. Also, about |
Feel free to raise new issues : ) |
Hi, I'm using flutter ably sdk. When testing on Android and IOS devices, when the app goes to the background and comes back to the foreground, there are times when the channel is not attached, but when the app comes back to the foreground, should I manage the realtime and channel?
┆Issue is synchronized with this Jira Bug by Unito
The text was updated successfully, but these errors were encountered: