Questions tagged [android-workmanager]
Android Jetpack WorkManager is used for scheduling and managing one time and periodic background tasks.
android-workmanager
1,349
questions
94
votes
10
answers
65k
views
More than one file was found with OS independent path 'META-INF/proguard/androidx-annotations.pro'
i am trying android WorkManager, The code is throwing error "More than one file was found with OS independent path 'META-INF/proguard/androidx-annotations.pro" when running, I tried the following ...
93
votes
7
answers
58k
views
Android WorkManager vs JobScheduler
Why do we need the new Android WorkManager if we already have a JobScheduler along with a few nifty backports (AndroidJob and FirebaseJobDispatcher) with the same functionality? Does it have any ...
88
votes
3
answers
64k
views
Android. Is WorkManager running when app is closed?
I want to schedule nightly database updates. So I use new Android WorkManager. My understanding is that once scheduled it will always run in the background independently from the app's lifecycle.
Is ...
83
votes
9
answers
60k
views
Schedule a work on a specific time with WorkManager
WorkManager is a library used to enqueue work that is guaranteed to execute after its constraints are met.
Hence, After going though the Constraints class I haven't found any function to add time ...
69
votes
2
answers
48k
views
How to create a Worker with parameters for in WorkManager for Android?
Android architecture has a new components WorkManager.
From the example,
class CompressWorker(context : Context, params : WorkerParameters)
: Worker(context, params) {
override fun doWork():...
65
votes
1
answer
42k
views
Android Work Manager vs Services?
In my Android app i have multiple intent services which run one after another and the very first intent service is trigerred by a broadcast. I came across Work Manager a few days ago and really liked ...
63
votes
4
answers
19k
views
How to solve 'Program type already present: com.google.common.util.concurrent.ListenableFuture'?
I am trying to use WorkManager 1.0.0-alpha09. and getting this error:
Program type already present:
com.google.common.util.concurrent.ListenableFuture
Message{kind=ERROR, text=Program type already ...
61
votes
7
answers
44k
views
Check if WorkManager is scheduled already
How can I check if WorkManager is scheduled already.
Here is my code that schedule WorkManager.
public static void scheduleWork() {
PeriodicWorkRequest.Builder photoCheckBuilder =
...
57
votes
9
answers
31k
views
Asynchronous Worker in Android WorkManager
Google recently announced new WorkManager architecture component. It makes it easy to schedule synchronous work by implementing doWork() in Worker class, but what if I want to do some asynchronous ...
57
votes
8
answers
75k
views
Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent, On AlarmPingSender
Problem
Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. I got it after updating target SDK to 31. the error always ...
48
votes
1
answer
21k
views
WorkManager vs AlarmManager, what to use depending on the case
I have to perform this use case (not code , just the right usage)
The use case : I need to fetch some data from the network everyday at 00:30 . These data provide me some specific times , and one of ...
45
votes
5
answers
63k
views
Android 12: Using SCHEDULE_EXACT_ALARM permission to get/show data at specific time are safe in Google Play Policy?
I have an Android app on Play store for 8 years. Recently Google release Android S or 12 introduce some limit with Foreground service launch restrictions
https://developer.android.com/about/versions/...
44
votes
2
answers
11k
views
How does setExpedited work and is it as good&reliable as a foreground service?
Background
In the past, I used a foreground IntentService to handle various events that come one after another. Then it was deprecated when Android 11 came (Android R, API 30) and it was said to ...
40
votes
15
answers
28k
views
Android Work Manager: "Could not instantiate Worker"
I've followed the Android Developer's tutorial on using the Worker Manager structure to run my code in background but anytime I try to enqueue my worker it doesn't run and I get the following error:
...
39
votes
4
answers
35k
views
Execute task every second using Work Manager API
Work Manager is a new API and I try to execute task every second, but it doesn't work.
This is my worker class
class TestingWorker : Worker(){
override fun doWork(): Result {
Log.i("...
33
votes
4
answers
14k
views
WorkManager - Should we remove the default initializer, when we use both Default initialization and Custom initialization?
I'm getting the following new error, when I upgrade WorkManager from "2.2.0" to "2.3.0-rc01"
The error occurs when I'm exporting APK.
C:\app: Error: Remove androidx.work.impl.WorkManagerInitializer ...
31
votes
6
answers
26k
views
IllegalStateException: WorkManager is already initialized
Having these dependencies:
dependencies {
implementation "androidx.work:work-runtime:2.0.1"
androidTestImplementation "androidx.work:work-testing:2.0.1"
}
When running this code for the ...
31
votes
2
answers
16k
views
How does WorkManager schedule GET requests to REST API?
I've had a look at the codelab for WorkManager plus some examples on here, but everything in code I have seen is either related to doing work locally on the device or work uploading to the server, not ...
29
votes
3
answers
23k
views
What are the retry strategy/ mechanism for WorkManager's OneTimeWorkRequest
I have the following one-time worker.
// Create a Constraints that defines when the task should run
Constraints constraints = new Constraints.Builder()
.setRequiredNetworkType(NetworkType....
29
votes
3
answers
23k
views
WorkManager.getInstance().cancelAllWorkByTag() not stopping the periodic job
for periodic task I am using work manager as:
PeriodicWorkRequest.Builder wifiWorkBuilder =
new PeriodicWorkRequest.Builder(FileUpload.class, 15,
...
27
votes
1
answer
12k
views
When to use JobIntentService vs WorkManager?
Google recently deprecated IntentService as of: https://android.googlesource.com/platform/frameworks/base.git/+/6f8b09029932dfd24945202017639754b00acc2e
The docs for IntentService now say:
* @...
25
votes
4
answers
14k
views
Dagger2: Unable to inject dependencies in WorkManager
So from what I read, Dagger doesn't have support for inject in Worker yet. But there are some workarounds as people suggest. I have tried to do it a number of ways following examples online but none ...
24
votes
3
answers
16k
views
How to pass own class into Worker in android?
How can we pass Serializable object in work manager by setData method of work manager? Is there any way to process with Work manager by passing object?
WorkManager is a library used to enqueue work ...
24
votes
3
answers
27k
views
Android 12 - Foreground service launch restrictions
I'm developing an SDK that needs to startForeground service from the background. Because it uses background location and Bluetooth-related works. If the application is killed, the monitoring is ...
23
votes
6
answers
30k
views
WorkManager not repeating the PeriodicWorkRequest
I am creating an android application to run my code in background. I'm well aware of the restriction introduced by the Android Oreo for background services and that's why I'm using WorkManager API to ...
23
votes
3
answers
2k
views
Why backup related process might cause Application's onCreate is not executed?
It is common to have Application class as follow
public class WeNoteApplication extends MultiDexApplication {
public static WeNoteApplication instance() {
return me;
}
@Override
...
22
votes
3
answers
17k
views
Set initial delay to a Periodic Work Manager in Android
I have a Worker instance that needs to run every 24 hours which is pretty simple considering the PeriodicWorkRequest API. But here's the catch.
If the user initiates the work at say 8 PM, I need the ...
22
votes
2
answers
11k
views
Android WorkManager: Cannot get output data from PeriodicWorkRequest
For some reasons I cannot get output data from PeriodicWorkRequest of Android WorkManager. The worker runs periodically as expected, it just doesn't return any data.
My MainActivity:
@Override
...
21
votes
6
answers
24k
views
Android WorkManager api for running daily task in Background
I need to call one API daily in the background even if the app is closed. I have seen about WorkManager API. For my scenario, I tried PeriodicWorkRequest but unfortunately, it's not working as my ...
21
votes
5
answers
7k
views
Synchronous or Asynchronous Rxjava inside the Worker (from WorkManager component) what's the right choice?
I'm new to the new architecture component WorkManager, I do my API calls via Retrofit and RxJava.
My use case here is to get new posts from the Backend, then show notification, and update a widget.
...
21
votes
2
answers
23k
views
Work Manager not working when app is killed by the user. Why?
I want to execute a task, even after the application is killed using work manager. But, the task is not executed after the app is killed.
workManager = WorkManager.getInstance();
Constraints ...
21
votes
5
answers
20k
views
How to schedule notifications using WorkManager?
I want to schedule a notification everytime the user add a note in the database for a specific time. While there are multiple ways to do it using AlarmManager, BroadcastReceiver etc. How can it be ...
21
votes
1
answer
5k
views
Is WorkerManager a realiable way to implement alarm/reminder feature in the app?
We notice that AlarmManagerCompat alone, isn't a reliable way to implement alarm/ reminder feature in our app, due to different AlarmManager behaviour in different version of OS. (For instance, Doze ...
20
votes
5
answers
24k
views
java.lang.IllegalStateException: Cannot invoke observeForever on a background thread
Can someone help me find where I am going wrong here. I need to continously observer network data and update the UI whenever there is a data change from the Worker. Please note that this was working ...
20
votes
1
answer
1k
views
Proper way to tackle and resolve "Excessive network usage (background)"
Problem Background
Currently, we have facing "Excessive network usage (background)" from Android Vital report. Last 30 days is 0.04%, but we're only Better than 9%
Last 30 days - 0.04%
Benchmark - ...
20
votes
1
answer
3k
views
How to implement Dagger for worker classes? [duplicate]
Since the Worker class is created by the framework (WorkerManager), how can we use @Inject fields into the Worker?
19
votes
3
answers
9k
views
Injecting CoroutineWorker with Hilt : Could not instantiate woker
Same questions have been asked but they didn't work for me , In the start I was using the latest version of work manager which is 2.7 alpha 3 but I downgraded since its only compatible to android 12 ...
19
votes
3
answers
19k
views
Periodic daily work requests using WorkManager
How to properly use the new WorkManager from Android Jetpack to schedule a one per day periodic work that should do some action on a daily basis and exactly one time?
The idea was to check if the ...
19
votes
3
answers
6k
views
Compile errors after updating to WorkManager 1.0.0-alpha09
I'm trying to use WorkManager from architecture components. I've upgraded the compileSdkVersion and targetSdkVersion from 27 to 28. gradle sync is successfully done. But build-time error keeps popping ...
19
votes
8
answers
12k
views
How to reduce time of PeriodicWorkManager in WorkManager
In PeriodicTimeRequest minimum periodic time is 15 minute. I want to reduce it from 15 min to less than 15 minute.How can i do that?
18
votes
4
answers
7k
views
foregroundServiceType 0x00000001 is not a subset of foregroundServiceType attribute 0x00000000 in service element of manifest file
I have implemented Foreground Service using WorkManager, it works fine upto API Level 33. Since it is mandatory in API Level 34 to specify foregroundServiceType, I specified it in Worker and in the ...
18
votes
4
answers
11k
views
Check if WorkRequest has been previously enquequed by WorkManager Android
I am using PeriodicWorkRequest to perform a task for me every 15 minutes.
I would like to check, if this periodic work request has been previously scheduled. If not, schedule it.
if (!...
18
votes
1
answer
2k
views
WorkManager - SystemForegroundService: Context.startForegroundService() did not then call Service.startForeground()
For fetching the location from foreeground service, we have recently migrated our WorkManager to use ForegroundService. We have followed the below document to achieve this:
https://developer.android....
17
votes
1
answer
9k
views
Avoiding duplicating PeriodicWorkRequest from WorkManager
On Application start I want to start service that will work forever, but when user opens app again it duplicates.
PeriodicWorkRequest.Builder sendDataBuilder = new PeriodicWorkRequest.Builder(...
17
votes
4
answers
21k
views
Unique OneTimeWorkRequest in Workmanager
We are using OneTimeWorkRequest to start background task in our project.
At application start, we are starting the OneTimeWorkRequest (say req A)
Depends on user's action we start the same work ...
16
votes
1
answer
9k
views
WorkManager's PeriodicWorkRequest is executing once and not repeating
I am trying to make use of WorkManager however I seem to be running into an issue where PeriodicSync is only repeated on startup once and that's it.
I've looked at this post Is WorkManager's ...
16
votes
3
answers
3k
views
WorkManager - how to execute jobs sequentially
I have a service listening for incoming FCM notifications. When such a notification is received, I run a job with WorkManager.
When multiple notifications are received at the same time, how can I ...
16
votes
7
answers
9k
views
PeriodicWorkRequest not working after device reboot in android oreo
I have requirement of pushing in app notification to user based on following logic.
Type A notification will be shown after every 24 hours.
Type B notification will be shown after every 7 days.
Type ...
15
votes
6
answers
10k
views
Android Studio class file for com.google.common.util.concurrent.ListenableFuture not found
I cannot build my project due to it failing because it cannot find a class. Is there something wrong with my sdk or dependancies?
I have tried invalidating cache and restarting. I am using api 29.
The ...
15
votes
3
answers
4k
views
How can I execute cleanup code in my CoroutineWorker when onStopped is final?
I upgraded to WorkManager 2.1.0 and tried to use some of the Kotlin extensions including CoroutineWorker. My worker was extending androidx.work.Worker previously and it was executing cleanup code by ...