Repository navigation
[Android] Timers do not run when using HeadlessJsTaskService #56324
Copy link
Copy link
Closed as not planned
Labels
Needs: Triage 🔍Platform: AndroidAndroid applications.Android applications.StaleThere has been a lack of activity on this issue and it may be closed soon.There has been a lack of activity on this issue and it may be closed soon.
Description
Description
Hello!
I noticed that when using HeadlessJsTaskService, the timers do not run as expected. I did some investigations and I found out that React Native uses Android's Choreographer to schedule the timers.
I am testing the app on a real device: Samsung Galaxy S22 Ultra.
Apparently, Samsung's OneUI pauses the Choreographer when the app goes into background.
In order to fix this, React Native should use another technique to get "ticks", like a Handler or something, at least for the timers (I saw UI events are also processed using Choreographer).
Steps to reproduce
- Install the application using "yarn android"
- Open up Android Studio with Logcat open
- Wait for the background service to start
- Put the app in foreground by going on the home screen
- Look in the logs and wait for the line with "CoreRune.SYSPERF_ACTIVE_APP_BBA_ENABLE : stop animation in background states"
React Native Version
0.84.1
Affected Platforms
Runtime - Android
Output of npx @react-native-community/cli info
System:
OS: macOS 26.3.1
CPU: (14) arm64 Apple M3 Max
Memory: 160.17 MB / 36.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 22.13.1
path: /Users/george/.nvm/versions/node/v22.13.1/bin/node
Yarn:
version: 3.6.4
path: /Users/george/.nvm/versions/node/v22.13.1/bin/yarn
npm:
version: 10.9.2
path: /Users/george/.nvm/versions/node/v22.13.1/bin/npm
Watchman:
version: 2025.05.26.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.16.2
path: /Users/george/.rvm/gems/ruby-3.0.0/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 25.0
- iOS 26.0
- macOS 26.0
- tvOS 26.0
- visionOS 26.0
- watchOS 26.0
Android SDK:
API Levels:
- "30"
- "31"
- "33"
- "34"
- "35"
- "36"
- "36"
Build Tools:
- 30.0.2
- 30.0.3
- 33.0.0
- 34.0.0
- 35.0.0
- 36.0.0
- 36.0.0
System Images:
- android-34 | Android TV ARM 64 v8a
- android-35 | ARM 64 v8a
- android-35 | Google Play ARM 64 v8a
- android-35 | Google Play Tablet ARM 64 v8a
- android-36 | Google Play ARM 64 v8a
- android-36 | Pre-Release 16 KB Page Size Google Play ARM 64 v8a
Android NDK: Not Found
IDEs:
Android Studio: 2025.3 AI-253.30387.90.2532.14935130
Xcode:
version: 26.0.1/17A400
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.13
path: /usr/bin/javac
Ruby:
version: 3.0.0
path: /Users/george/.rvm/rubies/ruby-3.0.0/bin/ruby
npmPackages:
"@react-native-community/cli":
installed: 20.1.0
wanted: 20.1.0
react:
installed: 19.2.3
wanted: 19.2.3
react-native:
installed: 0.84.1
wanted: 0.84.1
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: true
iOS:
hermesEnabled: Not found
newArchEnabled: false
Stacktrace or Logs
2026-04-04 17:31:59.258 11074-11128 ReactNativeJS com.choreographerissue I Hello from service!
2026-04-04 17:32:00.260 11074-11128 ReactNativeJS com.choreographerissue I Hello from service!
2026-04-04 17:32:01.264 11074-11128 ReactNativeJS com.choreographerissue I Hello from service!
2026-04-04 17:32:02.267 11074-11128 ReactNativeJS com.choreographerissue I Hello from service!
2026-04-04 17:32:02.526 11074-11074 Choreographer com.choreographerissue D CoreRune.SYSPERF_ACTIVE_APP_BBA_ENABLE : stop animation in background states
MANDATORY Reproducer
https://github.com/gmanole01/react-native-choreographer-issue
Screenshots and Videos
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Needs: Triage 🔍Platform: AndroidAndroid applications.Android applications.StaleThere has been a lack of activity on this issue and it may be closed soon.There has been a lack of activity on this issue and it may be closed soon.
Activity
pranjal2410719 commentedon Apr 5, 2026
Thanks for the detailed report and investigation — this is a great find.
However, the issue is slightly deeper than just Samsung pausing
Choreographer.🔍 Root cause
React Native timers (via
TimingModule) are currently driven byReactChoreographer, which ultimately relies on Android’sChoreographer(vsync / UI frame callbacks).This creates a hidden assumption:
That works fine in foreground apps, but breaks in background/headless scenarios.
On devices like Samsung (OneUI),
Choreographeris explicitly paused when the app goes to background (as seen in the logs), which means:So the real issue is:
Headless JS is designed for background execution, but:
This makes timers unreliable in any background execution context.
💡 Suggested fix (for React Native)
React Native should decouple timer scheduling from
Choreographerin non-UI contexts.A possible approach:
Choreographeronly when the app is in foreground / UI is activeHandler.postDelayedScheduledExecutorServiceIn other words, a dual scheduling strategy:
This would:
🧪 Workarounds (for others hitting this)
WorkManager,AlarmManager, or a foreground service)📌 Summary
This is not just a Samsung-specific issue — it reveals a design limitation in how React Native schedules timers. Fixing it would improve reliability of background execution across all Android devices.
gmanolek2 commentedon Apr 6, 2026
Hello, @pranjal2410719
Yes, I agree with you, the issue is a lot deeper. I have created a patch for React Native 0.84.1 in order to fix the issue.
This patch I created replaces ReactChoreographer used in the file
JavaTimerManager.ktwith ReactTimerChoreographer (class created by me) which usesHandler.postDelayedto drive the timers. This way, only the timers will use another ticking method, and the UI events and all the other things will use the Android'sChoreographer. Certainly my implementation is not the best. I set the Handler to run every 16.66ms (to achieve 60 ticks per second). Also, I commented the lines that pause the timers when the app goes into background and there are no headless tasks running, because I want the timers to run all the time.pranjal2410719 commentedon Apr 6, 2026
Hey @gmanolek2 — really nice work digging into this and putting together a patch 👏
This is a great proof-of-concept and makes it pretty clear that the root issue is tied to
Choreographerbeing paused in the background.I also like that you kept the change scoped to timers and didn’t touch UI-related callbacks — that’s a good call.
That said, I think there are a few things here that might make this tricky to use in production or upstream as-is:
1. Lifecycle handling
By commenting out
onHostPauseandonHeadlessJsTaskFinish, timers will keep running even when:That could lead to unnecessary CPU usage, battery drain, and possibly conflicts with Android’s background execution rules.
2. The 60 FPS loop
Using a
Handlerloop at ~16ms works, but it’s kind of simulating a frame loop rather than reacting to real timing signals.That might:
3. Not context-aware
Right now the scheduler is effectively replaced for timers in all cases.
Ideally, it would switch depending on context:
Choreographerwhen the app is active (UI)Handler/ executor when running headless💡 Possible direction
Instead of replacing the scheduler globally, maybe a better approach would be:
Choreographerfor normal UI-driven timersHandlerorScheduledExecutorService) only for Headless JSThat way you keep the benefits of both approaches without breaking lifecycle expectations.
📌 Overall
This patch does a really good job of proving the root cause and pointing in the right direction 👍
The next step would probably be making the scheduling strategy lifecycle-aware rather than always-on.
Would be great to keep iterating on this — feels like something worth fixing properly in core.
scrobble: re-trigger queue processing on app foreground (U17)
react-native-bot commentedon Oct 4, 2026
This issue is stale because it has been open for 180 days with no activity. It will be closed in 7 days unless you comment on it or remove the "Stale" label.
react-native-bot commentedon Oct 12, 2026
This issue was closed because it has been stalled for 7 days with no activity.