android-workmanager

Compile errors after updating to WorkManager 1.0.0-alpha09

99封情书 提交于 2019-12-05 03:14:14
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 up. android.support libraries are using version 28.0.0-rc02 because of the 'android.support:design'. I've tried to add packagingOptions in order to exclude 'proguard/androidx-annotations.pro'. But it didn't help. But this time I got a different error message: Program type already present: com.google.common.util.concurrent.ListenableFuture I could not figure out what's going wrong. build.gradle:

Android Work Manager: “Could not instantiate Worker”

↘锁芯ラ 提交于 2019-12-05 01:38:23
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: 2018-10-04 22:25:47.004 28669-28885/app.package.com.debug E/DefaultWorkerFactory: Could not instantiate app.package.com.MyWorker java.lang.NoSuchMethodException: <init> [] at java.lang.Class.getConstructor0(Class.java:2320) at java.lang.Class.getDeclaredConstructor(Class.java:2166) at androidx.work.DefaultWorkerFactory.createWorker(DefaultWorkerFactory.java:58) at androidx.work.impl.WorkerWrapper

Unique OneTimeWorkRequest in Workmanager

对着背影说爱祢 提交于 2019-12-04 19:13:27
问题 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 request A. At some cases, if the app gets killed when the work request A is in progress, Android automatically restarts the request A when the app restarts. Once again we are also starting the request A again. So two instances of the request A runs in parallel and leads to a deadlock. To avoid this, I

WorkManager doWork callback is not received in Redmi and other custom Chinese ROM when device got rebooted and force closed the app

邮差的信 提交于 2019-12-04 19:05:07
My app is not receiving push notification in Redmi phones while the app is in the background or it got killed by swiping. So I am trying to wake the phone by WorkManager which works on many phones except Redmi and other Chinese custom ROM phones. Here is my code of Worker class public class OpenTalkWorkManager extends Worker { @NonNull @Override public Result doWork() { Log.i("wake_up", "Waking up now: " + System.currentTimeMillis()); FirebaseUtils.getInstance().updateUserPresenceStatus(getApplicationContext(), "yes"); Intent intent = new Intent("com.opentalk.WAKE_UP"); getApplicationContext()

Avoiding duplicating PeriodicWorkRequest from WorkManager

时光怂恿深爱的人放手 提交于 2019-12-04 06:02:11
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(SendConnectionMetricsWorker.class, Constants.REPEAT_TIME_INTERVAL_IN_HOURS, Constants.REPEAT_TIME_INTERVAL_UNITS) .setConstraints(new Constraints.Builder() .setRequiredNetworkType(NetworkType.CONNECTED) .build()); PeriodicWorkRequest periodicWorkRequest = sendDataBuilder .build(); WorkManager.getInstance().enqueue(periodicWorkRequest); You can use enqueueUniquePeriodicWork instead of enqueue . Based on

Compile errors after updating to WorkManager 1.0.0-alpha09

╄→尐↘猪︶ㄣ 提交于 2019-12-04 02:46:37
问题 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 up. android.support libraries are using version 28.0.0-rc02 because of the 'android.support:design'. I've tried to add packagingOptions in order to exclude 'proguard/androidx-annotations.pro'. But it didn't help. But this time I got a different error message: Program type already present: com

Dagger2: Unable to inject dependencies in WorkManager

…衆ロ難τιáo~ 提交于 2019-12-03 18:42:07
问题 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 of them work for me. When I don't try to inject anything into the Worker class, the code works fine, only that I can't do what I want because I need access to some DAOs and Services. If I use @Inject on those dependencies, the dependencies are either null or the worker never starts i.e the

Set initial delay to a Periodic Work Manager in Android

孤人 提交于 2019-12-03 13:29:36
问题 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 first instance of the work manager to run at 9 AM the next morning and then follow the 24-hour periodic constraint. I looked hereand I found that the OneTimeWorkRequest API has a setInitialDelay() function that can be used but I wasn't able to find anything for the PeriodicWork API. Ther are some

Unique OneTimeWorkRequest in Workmanager

﹥>﹥吖頭↗ 提交于 2019-12-03 12:23:26
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 request A. At some cases, if the app gets killed when the work request A is in progress, Android automatically restarts the request A when the app restarts. Once again we are also starting the request A again. So two instances of the request A runs in parallel and leads to a deadlock. To avoid this, I did below code in app start to check if the worker is running but this always returns false. public

Set initial delay to a Periodic Work Manager in Android

醉酒当歌 提交于 2019-12-03 06:26:00
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 first instance of the work manager to run at 9 AM the next morning and then follow the 24-hour periodic constraint. I looked here and I found that the OneTimeWorkRequest API has a setInitialDelay() function that can be used but I wasn't able to find anything for the PeriodicWork API. Ther are some hacks for this such as I can use the OneTimeWork with the initial delay and then schedule a