Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WorkManager Stableに向けての所感

WorkManager Stableに向けての所感

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

Yoshihiro WADA

March 18, 2019
Tweet

More Decks by Yoshihiro WADA

Other Decks in Programming

Transcript

  1. 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() } }
  2. 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")
  3. 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)
  4. DB Worker GreedyScheduler ThreadPool JobSchedulers createBestAvailableBackgroundScheduler API Level 23 JobSchedulers

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

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

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

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

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

    Charging Constraint public @NonNull Builder setRequiresCharging(boolean requiresCharging) { this.mRequiresCharging = requiresCharging; return this; }