Execute task every second using Work Manager API

Its not working because, the minimum interval between two periodic work request is 15 min which is defined by MIN_PERIODIC_INTERVAL_MILLIS. Based on the documentation: Creates a PeriodicWorkRequest to run periodically once every interval period. The PeriodicWorkRequest is guaranteed to run exactly one time during this interval. The intervalMillis must be greater than or equal to … Read more

How does setExpedited work and is it as good&reliable as a foreground service?

Conceptually Foreground Services & Expedited Work are not the same thing. Only a OneTimeWorkRequest can be run expedited as these are time sensitive. Any Worker can request to be run in the foreground. That might succeed depending on the app’s foreground state. A Worker can try to run its work in the foreground using setForeground[Async]() … Read more

Asynchronous Worker in Android WorkManager

I used a countdownlatch and waited for this to reach 0, which will only happen once the asynchronous callback has updated it. See this code: public WorkerResult doWork() { final WorkerResult[] result = {WorkerResult.RETRY}; CountDownLatch countDownLatch = new CountDownLatch(1); FirebaseFirestore db = FirebaseFirestore.getInstance(); db.collection(“collection”).whereEqualTo(“this”,”that”).get().addOnCompleteListener(task -> { if(task.isSuccessful()) { task.getResult().getDocuments().get(0).getReference().update(“field”, “value”) .addOnCompleteListener(task2 -> { if (task2.isSuccessful()) … Read more