WorkManagerを使っていい塩梅でNotificationをする話

53d8d30d9da0439c4e32889c39285a9a?s=47 umakoz
March 14, 2019

 WorkManagerを使っていい塩梅でNotificationをする話

53d8d30d9da0439c4e32889c39285a9a?s=128

umakoz

March 14, 2019
Tweet

Transcript

  1. WorkManagerΛ࢖ͬͯ ͍͍ԘകͰ NotificationΛ͢Δ࿩ LINE Fukuoka അݟ ੣ @umakoz Android Night

    2019/3
  2. About me • LINE Fukuoka ։ൃ3ࣨ • അݟɹ੣ʢumami makotoʣ •

    @umakoz • LINE Creators Studio for Android • ! 3°02'03"
  3. LINE Creators Studio • εϚʔτϑΥϯ͔ΒLINEελϯϓ͕؆୯ʹ࡞ΕΔ • ࡱͬͨࣸਅΛՃ޻ͯ͠ελϯϓʹͰ͖Δ • ελϯϓͷ৹ࠪਃ੥΍ൢച͕Ͱ͖Δ https://creator.line.me/ja/studio/

  4. ࢓༷ ύοέʔδͷ࡞੒్தͰΞϓϦ͕ 7೔ؒىಈ͞Εͳ͔ͬͨΒ19࣌ʹ ʮ͋ͱNݸελϯϓΛ࡞ͬͯ ύοέʔδΛਃ੥͠·ͤΜ͔ʁʯ ͱ௨஌͢Δ

  5. WorkManager Background JobΛ؅ཧ͢ΔͨΊͷ Android Jetpack Component

  6. WorkManager key features 1 • API 14·ͰԼҐޓ׵ੑ͕͋Δ • API 23+ͷDeviceͰ͸JobSchedulerΛ࢖͏

    • API 13-22ͷDeviceͰ͸BroadcastReceiverͱ AlarmManagerΛ૊Έ߹Θͤͯ࢖͏ • Network͕࢖͑Δ͔ͱ͔Battery͕े෼͔ͳͲͷ੍໿Λ͚ͭͯ ࣮ߦͰ͖Δ
  7. WorkManager key features 2 • 1ճ͖Γ΍पظతͳTaskΛScheduleͰ͖Δ • Schduleͨ͠Taskͷ؅ཧʗ؂ࢹ͕Ͱ͖Δ • TaskΛ࿈࣮݁ͯ͠ߦͰ͖Δ

    • ͨͱ͑App΍Device͕࠶ىಈͯ͠΋Taskͷ࣮ߦΛอূ͢Δ
  8. OneTimeWork 1ճ͖ΓͷTask

  9. class SomeWorker( appContext: Context, workerParams: WorkerParameters ) : Worker(appContext, workerParams)

    { override fun doWork(): Result { // Do the work here return Result.success() } } val request = OneTimeWorkRequest .Builder(SomeWorker::class.java) .setInitialDelay(1, TimeUnit.HOURS) .build() WorkManager.getInstance() .enqueue(request)
  10. PeriodicWork पظతͳTask

  11. class SomeWorker( appContext: Context, workerParams: WorkerParameters ) : Worker(appContext, workerParams)

    { override fun doWork(): Result { // Do the work here return Result.success() } } val request = PeriodicWorkRequest .Builder(SomeWorker::class.java, 1, TimeUnit.HOURS) .build() WorkManager.getInstance() .enqueue(request)
  12. ࢓༷ ύοέʔδͷ࡞੒్தͰΞϓϦ͕ 7೔ؒىಈ͞Εͳ͔ͬͨΒ19࣌ʹ ʮ͋ͱNݸελϯϓΛ࡞ͬͯ ύοέʔδΛਃ੥͠·ͤΜ͔ʁʯ ͱ௨஌͢Δ

  13. ͋ͳͨͳΒͲ͏͢Δʁ

  14. PeriodicWork Interval 7days • ❌ AppͷىಈͰपظ͕ζϨΔ

  15. PeriodicWork Interval 1day • ❌ AppΛىಈͨ࣌͠ࠁʹTask͕࣮ߦ͞ΕΔ

  16. PeriodicWork Interval 1min • ❌ ͦ΋ͦ΋15෼Ҏ্ʹ͔͠IntervalΛઃఆͰ͖ͳ͍ ʢTaskͷ࠷௕࣮ߦ࣌ؒ͸10෼ʣ

  17. OneTimeWork InitialDelay 1min • ❌ ແବͳॲཧ͕ଟͯ͘ɺcode͕ෳࡶʹͳΔ

  18. PeriodicWork Interval 15min • ❌ ࠷େ14෼59ඵͷζϨΛڐ༰͠ͳ͍ͱ͍͚ͳ͍

  19. OneTimeWork + PeriodicWork • ⭕ OneTimeWorkͰ࣌ࠁௐ੔ͯ͠PeriodicWorkΛEnqueue

  20. ༨ஊ ͜ͷ࢓༷͸iOSʹͱͬͯΊͬͪΌਏ͍ App΍Device͕࠶ىಈͨ͠Β Taskͷ࣮ߦΛอূͰ͖ͳ͍

  21. ݁࿦ ࢓༷ʹΑͬͯ͸ WorkManagerΛ࢖ͬͯ΋ ׂͱ͠ΜͲ͍

  22. LINE͸ Android EngineerΛ ืू͍ͯ͠·͢!!!!!