WorkManager Stableに向けての所感

WorkManager Stableに向けての所感

2019/3/18に開催されたOtemachi.apk #2の発表資料です。当日はFirebaseJobDispatcher周りについて事実とは異なる発言をしているので修正したものになります。

0f50b010cc99988fba8a73008b21f353?s=128

Yoshihiro WADA

March 18, 2019
Tweet

Transcript

  1. WorkManager Stable Yoshihiro Wada a.k.a. @e10dokup Otemachi.apk #2 - 2019/03/18

    2019/3/20
  2. Yoshihiro Wada a.k.a. @e10dokup CyberAgant Inc. / Ameba Ameba

  3. WorkManager

  4. Android Jetpack compileSdkVersion 28 API Play Services JobScheduler/AlermManager/FirebaseJobDispatcher FirebaseJobDispatcher 1.0.0-alpha12

    FirebaseJobDispatcher deprecated etc WorkManager
  5. FirebaseJobDispatcher

  6. None
  7. WorkManager Stable 1.0.0 Released

  8. Beta RC Stable bug x Breaking API Changes 2018/12/12 1.0.0-alpha13

    Codelabs API Changes
  9. WorkManager

  10. Worker WorkManager WorkRequest Worker Request WorkManager Request WorkManager WorkManager WorkRequest

    WorkManager
  11. Worker doWork() WorkManager ˖ FYUFOET8PSLFSזؙٓأ׾甧ג׷ ˖ EP8PSL ⰻד䗳銲זⳢ椚׾鎸鶢ׅ׷ ˖ 䧭⸆٥㸣✪ח䘔ׄג8PSLFS3FTVMUTVDDFTT

    GBJMVSF ׾鵤ׅ 8PSLFS class MyWorker( context: Context, params: WorkerParameters ) : Worker(context, params) { override fun doWork(): Worker.Result { // Կ͔͠Βͷॲཧ return Worker.Result.success() } }
  12. WorkRequest optional Worker OneTimeWorkRequest - WorkRequest PeriodicWorkRequest - WorkRequest WorkManager

    ˖ 8PSLFSח㹋遤ח䗳銲ז⦼׾♷ִ׷ ˖ %BUBؙٓأ׾CVJME׃׋׮ך׾TFU*OQVU%BUBדTFUׅ׷ ˖ 8PSLFS⩎דכHFU*OQVU%BUBד《׶⳿ׅ 8PSL3FRVFTU // Workerʹ஋Λ༩͑Δ val data = Data.Builder().putString("KEY", "VALUE").build() OneTimeWorkRequest.Builder(MyWorker::class.java) .setInputData(data) .build() // WorkerͰ஋ΛऔΓग़͢ getInputData().getString("KEY")
  13. WorkManager WorkRequest enqueue WorkManager // Workerに値を与える val data = Data.Builder().putString(“KEY”,

    “VALUE”).build() OneTimeWorkRequest.Builder(MyWorker::class.java) .setInputData(data) .build() // Workerで値を取り出す getInputData().getString(“KEY”) ˖ 8PSL.BOBHFSFORVFVFׅ׷׌ֽ 欰䧭׃׋8PSL3FRVFTUך㹋遤 workManager = WorkManager.getInstance() val data = Data.Builder().putString("KEY", "VALUE").build() val request = OneTimeWorkRequest.Builder(MyWorker::class.java) .setInputData(data) .build() workManager.enqueue(request)
  14. potatotips 8PSL.BOBHFS :PTIJIJSP8BEBBLB!FEPLVQ BU1PUBUPUJQT ְתׁ׵ https://bit.ly/2UF3k4Q

  15. WorkManager Executor Constraints

  16. DB Worker GreedyScheduler ThreadPool JobSchedulers createBestAvailableBackgroundScheduler API Level 23 JobSchedulers

    Google Play Services FirebaseJobDispatcher AlermManager + BroadCastReceiver Executor ref: https://speakerdeck.com/takahirom/workmanager (58P)
  17. DB Worker GreedyScheduler ThreadPool JobSchedulers createBestAvailableBackgroundScheduler API Level 23 JobSchedulers

    AlermManager + BroadCastReceiver Executor ref: https://speakerdeck.com/takahirom/workmanager (58P)
  18. Constraints WorkRequest Constraints ˖ 8PSL3FRVFTU׾⡲׷媮ꥡד$POTUSBJOU׾♷ִ׷ֿהד㹋遤儗חⵖ秈׾⸇ִ׵׸׷ 8PSLך㹋遤朐䡾׾ⵖꣲ׃׋ְ // ୺຤͕ॆిதͰ͋Δ੍໿ΛՃ͑Δ val constraints

    = Constraints.Builder() .setRequiresCharging(true) .build() continuation = continuation.then( OneTimeWorkRequest.Builder(AWorker::class.java) .setConstraints(constraints) .build() )
  19. WorkManager Constraints NetworkType - BatterNotLow - Charging - StorageNotLow -

    DeviceIdle - Doze Idle API23 Constraints
  20. WorkManager Constraints NetworkType - BatterNotLow - Charging - StorageNotLow -

    DeviceIdle - Doze Idle API23 Constraints ConstraintController Tracker Constraints
  21. WorkManager Constraints NetworkType - BatterNotLow - Charging - StorageNotLow -

    DeviceIdle - Doze Idle API23 Constraints ConstraintController Tracker Constraints
  22. Constrains Builder Charging Constraints WorkManager TaskExecuter Worker WorkerFactory Tracker ConstraintController

    Charging Constraint public @NonNull Builder setRequiresCharging(boolean requiresCharging) { this.mRequiresCharging = requiresCharging; return this; }
  23. BatteryChargingController Room DB Charging Constraint BatteryChargingTracker ACTION_BATTERY_CHANGED intent ACTION_CHARGING /

    ACTION_POWER_CONNECTED Tracker Constraint Back-o Worker Charging Constraint
  24. https://android.googlesource.com/platform/frameworks/support/+/androidx- master-dev/work/workmanager/src/main/java/androidx/work/impl/constraints BatteryNotLow 15% ACTION_BATTERY_OKAY/LOW NetworkType ConnectivityManager METERED CONNECTED ROAMING

    StorageNotLow ACTION_DEVICE_STORAGE_OK / LOW API 26 AndroidManifest BroadcastReceiver deprecated BroadcastReceiver Constraints
  25. Executor Constraints Firebase JobDispatcher WorkManager migrating https://developer.android.com/topic/libraries/architecture/workmanager/ migrating-fb