Run widget updates from a background thread (#8553)

### Description

Run widget updates from a background thread
Closes #8546

### Checklist
<!-- 
To help us keep the issue tracker clean and work as efficient as
possible,
  please make sure that you have done all of the following.
You can tick the boxes below by placing an x inside the brackets like
this: [x]
-->
- [x] I have read the contribution guidelines:
https://github.com/AntennaPod/AntennaPod/blob/develop/CONTRIBUTING.md#submit-a-pull-request
- [x] I have performed a self-review of my code, going through my
changes line by line and carefully considering why this line change is
necessary
- [x] I have run the automated code checks using `./gradlew checkstyle
lint`
- [x] My code follows the style guidelines of the AntennaPod project:
https://antennapod.org/contribute/develop/app/code-style
- [x] I have mentioned the corresponding issue and the relevant keyword
(e.g., "Closes: #xy") in the description (see
https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
- [x] If it is a core feature, I have added automated tests
This commit is contained in:
Hans-Peter Lehmann
2026-06-29 22:46:50 +02:00
committed by GitHub
parent e977dad7fc
commit 7ad0ce618a

View File

@ -290,7 +290,8 @@ public class Media3PlaybackService extends MediaLibraryService {
PlaybackService.isRunning ? PlayerStatus.PLAYING : PlayerStatus.PAUSED,
(int) player.getContentPosition(), (int) player.getDuration(),
player.getPlaybackParameters().speed);
WidgetUpdater.updateWidget(Media3PlaybackService.this, widgetState);
Schedulers.io().scheduleDirect(() ->
WidgetUpdater.updateWidget(Media3PlaybackService.this, widgetState));
updatePlaybackPreferences();
// Auto-enable sleep timer when playback starts
@ -385,7 +386,8 @@ public class Media3PlaybackService extends MediaLibraryService {
WidgetUpdater.WidgetState widgetState = new WidgetUpdater.WidgetState(currentPlayable,
Util.shouldShowPlayButton(player) ? PlayerStatus.PAUSED : PlayerStatus.PLAYING,
(int) position, (int) duration, speed);
WidgetUpdater.updateWidget(this, widgetState);
Schedulers.io().scheduleDirect(() ->
WidgetUpdater.updateWidget(this, widgetState));
long currentTime = System.currentTimeMillis();
if (currentTime - lastPositionSaveTime >= POSITION_SAVE_INTERVAL_MS) {
saveCurrentPosition();