-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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] Dart timers unresponsive after coming from background #94094
Comments
Hi @davidmartos96, thanks for filing the issue. I attempted to reproduce the issue and for me, the snackbar seems responsive when coming back from the background. I have attached a video to show you what I see. Kindly let me know if you see the same thing or you experience something different. Tested on videotelegram-cloud-document-4-5830334588680932807.mp4 |
@danagbemava-nc Thanks for trying it out. I deeply believe this only happens on a specific set of devices, and it has to do with when the OS decides to sleep the app (pausing the Dart timers in the process). On my device it seems to be 1.5 min when the periodic timer stops printing every 20 s while the app is in the background. |
I see, thanks for the insight. I cannot reproduce on my current device. Labelling for further investigation. |
I've stumbled upon the issue after debugging a super bizarre bug. Basically, I've created buttons with a nice click animation:
Sometimes, after opening the app from the background, the buttons would get stuck in the pressed state and the future would finish after more than 20s of waiting. Note that it does not happen every time when opening the app from the background. It has to be there for some time and maybe other apps need to get open. Opening a lot of other apps after putting the app to the background seemed to reproduce the issue more reliably. I've figured that the issues must be with timers, as an other random component using a debounce mechanic (which uses a timer) did not work either. To investigate a bit further, I've added a timer in the main function.
After this addition, I could not reproduce the issue anymore. 🤯 As if having this timer would with all other timers. I've managed to get the issue on Pixel 8, Android 14 and Android simulator, API 34. I don't recall seeing it on iOS. |
Hello, I've encountered with this issue when the battery optimization setting on a One Plus 8T (Android 11) is active. This setting is active by default on the One Plus's and Xiaomis. I haven't been able to reproduce it in other devices. It may be possible to reproduce it as well on Android 12.
The issue appears when having a periodic timer, for instance every 20s and a simple timer that could be used under the hood in many places of the app, like a debounced search input. When the app goes to the background, the periodic timer will stop emitting event after about 1.5-2 minutes. Then, when the app goes to foreground, if we interact with the simple timer, it will be unresponsive, and will emit after several seconds (15-30s), even when configured to run in under a second.
One way to stop this issue from occurring is by "triggering" an empty Future after the app comes to the foreground.
Steps to Reproduce
Expected results:
The "debounced" timer should work after going to the foreground
Actual results:
The timer is unresponsive
Simplified logs of the execution
Code sample
Logs
The text was updated successfully, but these errors were encountered: