いまさらWorkManager

 いまさらWorkManager

2019/1/28に開催されたPotatotips #58にて発表した資料です

0f50b010cc99988fba8a73008b21f353?s=128

Yoshihiro WADA

January 28, 2019
Tweet

Transcript

  1. WorkManager Yoshihiro Wada a.k.a. @e10dokup 2019/1/28 at Potatotips #58

  2. a.k.a. e10dokup CyberAgent Inc. Ameba

  3. None
  4. 2018/12/23 - 1.0.0-beta01 2019/1/15 1.0.0-beta02 2018/12/12 - 1.0.0-alpha13 Breaking Change

    Codelabs WorkManager
  5. Android Jetpack compileSdkVersion 28 API Play Services JobScheduler/AlermManager/ FirebaseJobDispatcher etc

    WorkManager
  6. Worker WorkManager WorkRequest Worker Request WorkManager Request WorkManager WorkManager WorkRequest

  7. extends Worker doWork() Worker.Result.success() / failure() Worker class MyWorker( context:

    Context, params: WorkerParameters ) : Worker(context, params) { override fun doWork(): Worker.Result { // Կ͔͠Βͷॲཧ return Worker.Result.success() } }
  8. Worker Data build setInputData set Worker getInputData WorkRequest // Workerʹ஋Λ༩͑Δ

    val data = Data.Builder().putString("KEY", "VALUE").build() OneTimeWorkRequest.Builder(MyWorker::class.java) .setInputData(data) .build() // WorkerͰ஋ΛऔΓग़͢ getInputData().getString("KEY")
  9. OneTimeWorkRequest Worker Request PeriodicWorkRequest Worker Request WorkRequest

  10. WorkManager#enqueue WorkRequest workManager = WorkManager.getInstance() val data = Data.Builder().putString("KEY", "VALUE").build()

    val request = OneTimeWorkRequest.Builder(MyWorker::class.java) .setInputData(data) .build() workManager.enqueue(request)
  11. WorkManager#beginWith Continuation then Work Continuation#enqueue Work // AWorker -> BWorker

    -> CWorkerͷॱʹ࣮ߦ͞Ε͍ͯ͘WorkContinuation val continuation = workManager.beginWith(OneTimeWorkRequest.from(AWorker::class.java)) continuation.then(OneTimeWorkRequest.from(BWorker::class.java)) continuation.then(OneTimeWorkRequest.from(CWorker::class.java)) continuation.enqueue()
  12. WorkManager#beginUniqueWork ExistingWorkPolicy REPLACE - KEEP - APPEND - Work -

    var continuation = workManager.beginUniqueWork( "unique_work_id", ExistingWorkPolicy.REPLACE, OneTimeWorkRequest.from(AWorker::class.java) )
  13. WorkRequest Constraint Work // ୺຤͕ॆిதͰ͋Δ੍໿ΛՃ͑Δ val constraints = Constraints.Builder() .setRequiresCharging(true)

    .build() continuation = continuation.then( OneTimeWorkRequest.Builder(AWorker::class.java) .setConstraints(constraints) .build() )
  14. NetWorkType - BatteryNotLow - Charging - StorageNotLow - DeviceIdle -

    API23 Doze Idle Work
  15. WorkRequest tag set WorkStatus uniqueId Continuation LiveData RxJava2 -> RxWorker

    1.0.0-alpha12 Codelabs 2-3