WorkManager beginUniqueWork doesn't work as expected

前端 未结 2 1554
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-14 17:44

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         


        
相关标签:
2条回答
  • 2021-02-14 18:22

    The answer from @ianhanniballake is of course helpful and correct, but I thought I'd point out that (with a fast-evolving API) there is a new enqueueUniqueWork() method so I guess the OP could now use:

    workManager.enqueueUniqueWork(
        SyncWorker.TAG,
        ExistingWorkPolicy.REPLACE,
        oneTimeWorkRequest
    );
    
    0 讨论(0)
  • 2021-02-14 18:38

    beginUniqueWork() returns a WorkContinuation object. You need to call enqueue on that WorkContinuation to actually enqueue it with WorkManager:

    workManager.beginUniqueWork(
        SyncWorker.TAG,
        ExistingWorkPolicy.REPLACE,
        oneTimeWorkRequest
    ).enqueue();
    
    0 讨论(0)
提交回复
热议问题