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

AndroidXに潜む便利なヤツら

 AndroidXに潜む便利なヤツら

E28404a128b6014e6f499d2a967c72a0?s=128

Takuji Nishibayashi

April 19, 2019
Tweet

Transcript

  1. AndroidXʹજΉศརͦ͏ͳϠπΒ @takuji31 Mobile Act KYOTO #1

  2. ࣗݾ঺հ

  3. ࣗݾ঺հ • @takuji31 id:takuji31 • Takuji Nishibayashi • Hatena Co.,

    Ltd. • App Team • ίϛοΫDAYS • δϟϯϓϧʔΩʔʂ • ΧΫϤϜ
  4. ࣗݾ঺հ • Android • Kotlin • Flu-er • ! h-ps:/

    /blog.takuji31.jp • " h-ps:/ /nazuna.takuji31.jp • # $ h-ps:/ /photo.takuji31.jp
  5. AndroidX

  6. LiveData? ViewModel? AppCompat? Naviga5on

  7. ࢖ͬͯ·͢ΑͶ

  8. ศརͳ΍ͭ৭ʑ঺հ͠·͢

  9. α൛ͷ΋ͷ΋ؚ·ΕΔͷͰ ͝ར༻͸ܭըతʹ

  10. ଞʹ΋͍͍΋ͷ͋ͬͨΒ ڭ͍͑ͯͩ͘͞ʂ

  11. androidx.ac*vity androidx.fragment

  12. ComponentActivity.viewModels{} Fragment.viewModels{} Fragment.activityViewModels{}

  13. ViewModelΛऔಘͰ͖Δ Delegated property

  14. viewModels ͸Ҿ਺Ͱ ViewModelStoreOwnerΛ୳͢ blockΛ౉ͤΔ

  15. valʹͰ͖Δ

  16. Goodbye! private lateinit var

  17. @ContentView

  18. ComponentAc*vity ͱ Fragmentʹ secondory constructor͕௥Ճ

  19. constructorͷҾ਺ʹLayoutͷIDΛ ౉ͤΔ

  20. Goodbye setContentView()

  21. DataBinding͸bind͢Ε͹Αͦ͞͏

  22. androidx.lifecycle

  23. ViewModelͱ͔LiveDataͱ͔ೖͬͯ ΔΞϨ

  24. ViewModel.viewModelScope

  25. ViewModelͷCorou,neScope

  26. Context͸ Dispatchers.Main + Job

  27. onCleared() ͰΩϟϯηϧ

  28. Saved State

  29. ViewModel͸ը໘ճసΛੜ͖࢒Δ

  30. Ac#vity͕ϝϞϦʔ͔Β ഁغ͞ΕΔ࣌͸ࢮ͵

  31. SavedStateHandler Ͱঢ়ଶΛ෮ݩͰ͖Δ

  32. γϯϓϧͳ set/get/remove/contains

  33. getLiveData()

  34. see. h&ps:/ /developer.android.com/ topic/libraries/architecture/ viewmodel-savedstate

  35. androidx.navigation

  36. Naviga&onͷΞϨ

  37. androidx.navigation.safeargs androidx.navigation.safeargs.kotlin

  38. Naviga&onͷxmlʹఆٛͨ͠ભҠઌ ͷargsΛࣗಈੜ੒

  39. Kotlinίʔυੜ੒Մೳ

  40. Goodbye createIntent() methods!

  41. Naviga&onͰը໘ભҠ͠ͳͯ͘΋࢖ ͑Δ

  42. ·ͣ͸࢖ͬͯΈͯʂ

  43. Fragment.navGraphViewModels()

  44. ࢦఆͨ͠Naviga&onͷgraphͰੜ͖ ࢒ΔFragment

  45. NavHostFragment಺ͷFragment಺ Ͱ࢖͏ɺΈ͍ͨͳײ͡ͷ࣌ʹ࢖͑ͦ ͏

  46. ͜Εॻ͍ͯͯࠓ࣮૷ͯ͠Δը໘Ͱ࢖ ͑ͦ͏ͱࢥͬͨͷͰ࢖͏༧ఆ

  47. h"ps:/ /developer.android.com/ jetpack/androidx