Skip to content

Commit 35cfea4

Browse files
authored
Merge pull request #148 from herethesavior/fix/expedited-widget-updates
fix: run widget updates as expedited work so they aren't deferred
2 parents 9cbfed9 + befbeef commit 35cfea4

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## Fixed
11+
12+
- Use expedited WorkManager requests for widget background tasks on Android 12+ to reduce delays when the app is in the background, with fallback to regular work when expedited quota is exhausted.
13+
1014
## [0.20.3] - 2026-05-02
1115

1216
## Fixed

android/src/main/java/com/reactnativeandroidwidget/RNWidgetJsCommunication.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.reactnativeandroidwidget;
22

33
import android.content.Context;
4+
import android.os.Build;
45

56
import androidx.work.Data;
67
import androidx.work.ExistingWorkPolicy;
78
import androidx.work.OneTimeWorkRequest;
9+
import androidx.work.OutOfQuotaPolicy;
810
import androidx.work.WorkManager;
911

1012
import java.util.concurrent.TimeUnit;
@@ -22,14 +24,19 @@ public static void requestWidgetUpdate(Context context, String widgetName) {
2224
protected static void startBackgroundTask(Context context, Data data) {
2325
workManagerWorkaround(context);
2426

25-
OneTimeWorkRequest headlessJsTaskWorkRequest =
27+
OneTimeWorkRequest.Builder builder =
2628
new OneTimeWorkRequest.Builder(RNWidgetBackgroundTaskWorker.class)
27-
.setInputData(data)
28-
.build();
29+
.setInputData(data);
30+
31+
// Reduce background scheduling delays on Android 12+.
32+
// Falls back to regular work if expedited quota is exhausted.
33+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
34+
builder.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST);
35+
}
2936

3037
WorkManager
3138
.getInstance(context)
32-
.enqueue(headlessJsTaskWorkRequest);
39+
.enqueue(builder.build());
3340
}
3441

3542
// `APPWIDGET_UPDATE` (`onUpdate`) method is called when the WorkManager queue is empty.

0 commit comments

Comments
 (0)