android-workmanager

WorkManger works on Oreo but not Lollipop

半城伤御伤魂 提交于 2019-12-11 00:23:42
问题 WorkManager states that it works on OSes before JobScheduler and the like, yet it doesn't seem to work on API levels that use AlarmManager . I have a PeriodicWorkRequest which runs in intervals just fine on Oreo, but on Lollipop, it only runs the first time. The code in question ( PeriodicWorker.class is my own class of course): WorkManager .getInstance() .enqueue( new PeriodicWorkRequest.Builder( PeriodicWorker.class, PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS, TimeUnit.MILLISECONDS )

How to make sure that WorkManager cancels my Worker?

混江龙づ霸主 提交于 2019-12-10 20:51:17
问题 It's mentioned in WorkManager documentation that cancelling a Worker is best-effort WorkManager makes its best effort to cancel the task, but this is inherently uncertain--the task may already be running or finished when you attempt to cancel it What if i have a use case that it's mandatory that the Worker gets cancelled upon calling one of the cancelling methods? 回答1: As you wrote WorkManager can only try with a best-effort to cancel a work. In particular, if a task is scheduled to run, and

Compile errors after updating to WorkManager 1.0.0-alpha09

*爱你&永不变心* 提交于 2019-12-10 03:31:58
问题 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

Why is Android Worker finishing successfully and calling onStopped()

女生的网名这么多〃 提交于 2019-12-09 03:15:25
问题 My current Android app employs androidx.work:work-runtime:2.2.0-rc01 My Worker code resembles this:- class SyncWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) { private var syncWorkerResult: Result = Result.success() override fun doWork(): Result { return syncWorkerResult } override fun onStopped() { Log.i(TAG, "onStopped() $isStopped") super.onStopped() } } As far as I understand the docs for Worker I shouldnt be seeing the following logs:- 2019-08-21

How to use WorkManager to run a long running job in Foreground

感情迁移 提交于 2019-12-08 10:34:14
问题 Due to the problem mentioned in Proper way to tackle and resolve "Excessive network usage (background)" , I plan to move the long running task (sync to cloud) from background to foreground. Currently, I start my delayed WorkManager in Application 's onPause I was planning to use WorkManager , to launch an IntentService 's startForeground - Android - implementing startForeground for a service? But, WorkManager itself unable to launch a Service . May I know how I can achieve so? Is there a way,

Android Work Manager - Does Work Manager will 100% ensure the background execution to be Completed?

青春壹個敷衍的年華 提交于 2019-12-07 14:20:19
问题 From what I read from the documentation https://developer.android.com/topic/libraries/architecture/workmanager, It said that: The task is still guaranteed to run, even if your app is force-quit or the device is rebooted. So which mean, the execution that being at the background will 100% be execute until it complete no matter what? For an example case: An Apps have Button that perform Work Manager Implementation that upload data to an Online Database but it required Internet Connection to

Handle response of WorkManager on Network connection Failure

梦想与她 提交于 2019-12-07 04:49:44
问题 I'm using WorkManager to sync data from my local Room database to server. The issue is that Room gives error to build database in Loop.MainLooper() and when i use it as following it works fine. But I'm unable to return the 'WorkerResult' on SUCCESS or RETRY based upon task completion. How to stop worker when Netwrok is lost? public class TestSyncManager extends Worker { private final WorkerResult[] workerResult = {WorkerResult.SUCCESS}; // @Inject // Dagger2 has not added the support for

Android Work Manager - Does Work Manager will 100% ensure the background execution to be Completed?

巧了我就是萌 提交于 2019-12-06 01:55:35
From what I read from the documentation https://developer.android.com/topic/libraries/architecture/workmanager , It said that: The task is still guaranteed to run, even if your app is force-quit or the device is rebooted. So which mean, the execution that being at the background will 100% be execute until it complete no matter what? For an example case: An Apps have Button that perform Work Manager Implementation that upload data to an Online Database but it required Internet Connection to upload the data. So, my Apps is currently in Offline Mode and I click the Button. My Uncertainty: Will

WorkManager beginUniqueWork doesn't work as expected

那年仲夏 提交于 2019-12-06 00:51:09
问题 Currently, I'm using WorkManager 1.0.0-alpha02. def work_version = "1.0.0-alpha02" implementation "android.arch.work:work-runtime:$work_version" // use -ktx for Kotlin // optional - Firebase JobDispatcher support implementation "android.arch.work:work-firebase:$work_version" I have no problem to execute background worker, by using the following code, when the app quit. Use enqueue, work as expected OneTimeWorkRequest oneTimeWorkRequest = new OneTimeWorkRequest.Builder(SyncWorker.class)

Handle response of WorkManager on Network connection Failure

旧巷老猫 提交于 2019-12-05 11:37:00
I'm using WorkManager to sync data from my local Room database to server. The issue is that Room gives error to build database in Loop.MainLooper() and when i use it as following it works fine. But I'm unable to return the 'WorkerResult' on SUCCESS or RETRY based upon task completion. How to stop worker when Netwrok is lost? public class TestSyncManager extends Worker { private final WorkerResult[] workerResult = {WorkerResult.SUCCESS}; // @Inject // Dagger2 has not added the support for dependency injection in worker yet. private ApiHeader mApiHeader; private HandlerThread mHandlerThread;