Single Activity by Example (Droidcon Italy 2019)

Single Activity by Example (Droidcon Italy 2019)

Slides for presentation given at Droidcon Italy 2019

Sample project here: https://github.com/remcomokveld/SingleActivity-DroidconIT

856e42fdebde4aed59621710ef899984?s=128

remcomokveld

April 04, 2019
Tweet

Transcript

  1. None
  2. None
  3. Single Activity by Example By Remco Mokveld 2

  4. Why this talk? Single Activity by Example 3

  5. Disney Streaming Services –Twitter User “Until they really fix Backstack

    Management with fragments this is still going to be painful.” 4
  6. Disney Streaming Services –Twitter User “Don’t get the Single Activity

    hype. It doesn’t scale.” 5
  7. Disney Streaming Services –Twitter User “Big projects should be split

    up in feature modules, one Activity per feature.” 6
  8. Disney Streaming Services –Twitter User “Single activity makes it too

    easy to create spaghetti, that is likely going to be what you get. Multiple activities force you to decouple better.” 7
  9. Points to discuss • Fragment Back Stack • Single Activity

    Scalability 8
  10. Disney Streaming Services 9

  11. Disney Streaming Services 9

  12. Disney Streaming Services 9

  13. Disney Streaming Services 9

  14. Disney Streaming Services 9

  15. Disney Streaming Services 9

  16. Disney Streaming Services 9

  17. Disney Streaming Services 9

  18. Disney Streaming Services 9

  19. Disney Streaming Services 9

  20. Disney Streaming Services 9

  21. Disney Streaming Services 9

  22. Fragment Navigation Back stack issues? 10

  23. Disney Streaming Services 11 What is a backstack?

  24. Disney Streaming Services What is a back stack? 11

  25. Disney Streaming Services Stack of cards 12

  26. Disney Streaming Services Only the top card is visible 13

  27. Disney Streaming Services 13 Only the top fragment has a

    View
  28. Disney Streaming Services All Fragments in the stack are CREATED

    14
  29. Disney Streaming Services 15

  30. Disney Streaming Services 15

  31. Disney Streaming Services 15

  32. Disney Streaming Services 16 FragmentA

  33. Disney Streaming Services 16 FragmentA onCreate

  34. Disney Streaming Services 16 FragmentA onCreate CREATED

  35. Disney Streaming Services 16 FragmentA CREATED onCreateView

  36. Disney Streaming Services 16 FragmentA CREATED onStart

  37. Disney Streaming Services 16 FragmentA onStart STARTED

  38. Disney Streaming Services 16 FragmentA STARTED onResume

  39. Disney Streaming Services 16 FragmentA onResume RESUMED

  40. Disney Streaming Services 16 FragmentA FragmentB onResume RESUMED

  41. Disney Streaming Services 16 FragmentA FragmentB RESUMED onPause

  42. Disney Streaming Services 16 FragmentA FragmentB onPause STARTED

  43. Disney Streaming Services 16 FragmentA FragmentB STARTED onStop

  44. Disney Streaming Services 16 FragmentA FragmentB onStop CREATED

  45. Disney Streaming Services 16 FragmentA FragmentB CREATED onDestroyView

  46. Disney Streaming Services 16 FragmentA FragmentB CREATED onCreate

  47. Disney Streaming Services 16 FragmentA FragmentB CREATED onCreate CREATED

  48. Disney Streaming Services 16 FragmentA FragmentB CREATED CREATED onCreateView

  49. Disney Streaming Services 16 FragmentA FragmentB CREATED CREATED onStart

  50. Disney Streaming Services 16 FragmentA FragmentB CREATED onStart STARTED

  51. Disney Streaming Services 16 FragmentA FragmentB CREATED STARTED onResume

  52. Disney Streaming Services 16 FragmentA FragmentB CREATED onResume RESUMED

  53. Disney Streaming Services 16 FragmentA FragmentB CREATED RESUMED onPause

  54. Disney Streaming Services 16 FragmentA FragmentB CREATED onPause STARTED

  55. Disney Streaming Services 16 FragmentA FragmentB CREATED STARTED onStop

  56. Disney Streaming Services 16 FragmentA FragmentB CREATED onStop CREATED

  57. Disney Streaming Services 16 FragmentA FragmentB CREATED CREATED onDestroyView

  58. Disney Streaming Services 16 FragmentA FragmentB CREATED CREATED onDestroy

  59. Disney Streaming Services 16 FragmentA FragmentB CREATED onDestroy DESTROYED

  60. Disney Streaming Services 16 FragmentA CREATED

  61. Disney Streaming Services 16 FragmentA CREATED onCreateView

  62. Disney Streaming Services 16 FragmentA CREATED onStart

  63. Disney Streaming Services 16 FragmentA onStart STARTED

  64. Disney Streaming Services 16 FragmentA STARTED onResume

  65. Disney Streaming Services 16 FragmentA onResume RESUMED

  66. Disney Streaming Services Unnecessary view creation 17

  67. Disney Streaming Services setReorderingAllowed 18

  68. Disney Streaming Services 19

  69. Disney Streaming Services 19

  70. Disney Streaming Services onCreate onCreateView onStart onResume First Transaction onPause

    onStop onDestroyView Second Transaction onCreate onCreateView onStart onResume
  71. Disney Streaming Services onCreate onCreateView onStart First Transaction onStop onDestroyView

    Second Transaction onCreate onCreateView onStart onResume onResume onPause
  72. Disney Streaming Services onCreate onCreateView onStart First Transaction onStop onDestroyView

    Second Transaction onCreate onCreateView onStart onResume
  73. Disney Streaming Services onCreate onCreateView First Transaction onDestroyView Second Transaction

    onCreate onCreateView onStart onResume onStart onStop
  74. Disney Streaming Services onCreate onCreateView First Transaction onDestroyView Second Transaction

    onCreate onCreateView onStart onResume
  75. Disney Streaming Services onCreate First Transaction Second Transaction onCreate onCreateView

    onStart onResume onCreateView onDestroyView
  76. Disney Streaming Services onCreate First Transaction Second Transaction onCreate onCreateView

    onStart onResume
  77. Disney Streaming Services 21 ScreenA

  78. Disney Streaming Services 21 ScreenA onCreate CREATED

  79. Disney Streaming Services 21 ScreenA ScreenB CREATED onCreate CREATED

  80. Disney Streaming Services 21 ScreenA ScreenB CREATED CREATED onCreateView

  81. Disney Streaming Services 21 ScreenA ScreenB CREATED onStart STARTED

  82. Disney Streaming Services 21 ScreenA ScreenB CREATED onResume RESUMED

  83. Disney Streaming Services 21 ScreenA ScreenB CREATED onPause STARTED

  84. Disney Streaming Services 21 ScreenA ScreenB CREATED onStop CREATED

  85. Disney Streaming Services 21 ScreenA ScreenB CREATED CREATED onDestroyView

  86. Disney Streaming Services 21 ScreenA ScreenB CREATED onDestroy

  87. Disney Streaming Services 21 ScreenA CREATED onCreateView

  88. Disney Streaming Services 21 ScreenA onStart STARTED

  89. Disney Streaming Services 21 ScreenA onResume RESUMED

  90. Disney Streaming Services Primary Navigation Fragment 22

  91. Disney Streaming Services 23 Splash Onboarding MainActivity FavoriteTeam Paywall SignIn

    MainApp MyTeam ScoreBoard ScoreBoard
  92. Disney Streaming Services 23 Splash Onboarding MainActivity FavoriteTeam Paywall SignIn

    MainApp MyTeam ScoreBoard ScoreBoard
  93. Disney Streaming Services 23 Splash Onboarding MainActivity FavoriteTeam Paywall SignIn

    MainApp MyTeam ScoreBoard ScoreBoard
  94. Disney Streaming Services 23 Splash Onboarding MainActivity FavoriteTeam Paywall SignIn

    MainApp MyTeam ScoreBoard ScoreBoard
  95. Disney Streaming Services 23 Splash Onboarding MainActivity FavoriteTeam Paywall SignIn

    MainApp MyTeam ScoreBoard ScoreBoard
  96. Disney Streaming Services 23 Splash Onboarding MainActivity FavoriteTeam Paywall SignIn

    MainApp MyTeam ScoreBoard MatchDetail
  97. Disney Streaming Services 23 Splash Onboarding MainActivity FavoriteTeam Paywall SignIn

    MainApp MyTeam ScoreBoard MatchDetail
  98. Disney Streaming Services 23 Splash Onboarding MainActivity FavoriteTeam Paywall SignIn

    MainApp MyTeam ScoreBoard MatchDetail
  99. Disney Streaming Services Required for nested back stacks 24

  100. Disney Streaming Services 25

  101. Disney Streaming Services 26

  102. Disney Streaming Services 26

  103. Disney Streaming Services 26

  104. Disney Streaming Services 26

  105. Disney Streaming Services 26

  106. Disney Streaming Services 26

  107. Disney Streaming Services 26 OUTDATED

  108. Disney Streaming Services As of activity:1.0.0-alpha06 OnBackPressedDispatcher 27

  109. Disney Streaming Services Two Fragment navigation functions 28

  110. Disney Streaming Services 29

  111. Disney Streaming Services 30

  112. Scalability Single Activity by Example 31

  113. Disney Streaming Services Activity is the single entry point of

    each app 32
  114. Disney Streaming Services Fragment is the single entry point of

    each feature 33
  115. Disney Streaming Services Activity represents an entire user session 34

  116. Disney Streaming Services Fragments represent individual screens or flows 35

  117. Disney Streaming Services Fragments represent individual screens or flows 36

  118. Onboarding flow Single Activity by Example 37

  119. Disney Streaming Services IAP back behavior 38

  120. Disney Streaming Services IAP back behavior 38 FollowTeam

  121. Disney Streaming Services IAP back behavior 38

  122. Disney Streaming Services IAP back behavior 38 FollowTeam

  123. Disney Streaming Services IAP back behavior 38 FollowTeam SignUp

  124. Disney Streaming Services Lots of different screens 39

  125. Disney Streaming Services Complex back logic 40

  126. Disney Streaming Services OnboardingActivity? 41

  127. Disney Streaming Services Is onboarding done? 42

  128. Disney Streaming Services 43 LoginFragment SignUpFragment OnboardingFragment FollowTeamFragment IAPFragment PaywallFragment

  129. Disney Streaming Services replaceStack(OnboardingFragment()) 44

  130. Disney Streaming Services class NHLActivity : Activity(), OnboardingHost 45

  131. Disney Streaming Services 46

  132. Disney Streaming Services “Type a quote here.” 47

  133. Disney Streaming Services Find interface in parents 48

  134. Disney Streaming Services 49

  135. Disney Streaming Services 49

  136. Disney Streaming Services 49

  137. Disney Streaming Services 49

  138. Disney Streaming Services 49

  139. Disney Streaming Services 49

  140. Disney Streaming Services What about that custom back behavior? 50

  141. Disney Streaming Services 51

  142. Bottom Navigation Single Activity by Example 52

  143. Disney Streaming Services (Almost) According to material.io (as of today)

    53
  144. Disney Streaming Services Builds a stack within each tab 54

    MyTeam
  145. Disney Streaming Services Builds a stack within each tab 54

    MyTeam
  146. Disney Streaming Services Switching tabs should reset the back stack

    55 MyTeam
  147. Disney Streaming Services Switching tabs should reset the back stack

    55 MyTeam
  148. Disney Streaming Services Switching tabs should reset the back stack

    55 MyTeam
  149. Disney Streaming Services Back on first tab closes the app

    56
  150. Disney Streaming Services Back on first tab closes the app

    56
  151. Disney Streaming Services Back on first tab closes the app

    56
  152. Disney Streaming Services Pressing back on second and third top-level

    tab takes you to the first 57 MyTeam
  153. Disney Streaming Services Pressing back on second and third top-level

    tab takes you to the first 57 MyTeam
  154. Disney Streaming Services Pressing tab item while on top level

    resets content 58
  155. Disney Streaming Services Pressing tab item while on top level

    resets content 58
  156. Disney Streaming Services 59

  157. Startup checks Single Activity by Example 60

  158. Disney Streaming Services Needs to be done on every startup

    61
  159. Disney Streaming Services Pre fetch data 62

  160. Disney Streaming Services Lapsed subscription check 63

  161. Disney Streaming Services Fetch A/B Configs 64

  162. Disney Streaming Services SplashActivity? 65

  163. Disney Streaming Services SingleActivity.onCreate 66

  164. Disney Streaming Services 67

  165. Disney Streaming Services 68

  166. Key Takeaways & Tips Single Activity by Example 69

  167. Disney Streaming Services Nesting Fragments is good 70

  168. Disney Streaming Services Every UI feature can be built in

    a Fragment 71
  169. Disney Streaming Services If a feature becomes too big, split

    your Fragment into multiple (child) Fragments 72
  170. Disney Streaming Services Fragments should never depend on their host

    73
  171. Disney Streaming Services Fragments should depend on their host implementing

    an interface 74
  172. Disney Streaming Services Always use Primary Navigation Fragment 75

  173. Disney Streaming Services Always use setReorderingAllowed 76

  174. Disney Streaming Services Single Activity gives you full control over

    your back stack 77
  175. Fragment Caveats Single Activity by Example 78

  176. Disney Streaming Services Only do initial navigation when savedInstanceState ==

    null 79
  177. Disney Streaming Services Don’t mixup fragmentManager and childFragmentManager 80

  178. Disney Streaming Services For navigation screens always: Add to back

    stack Or Replace the back stack 81
  179. Disney Streaming Services Transitions support is… 82

  180. Disney Streaming Services bit.ly/droidcon-it-single-activity 83

  181. Thank you! Questions?