You've been told lies about Fragments
summary
Fragments produce surprising lifecycle behavior: XML-declared fragments inflate views during activity onCreate while code-added fragments populate in onStart, commitNow vs commit differences cause timing bugs, and ViewPager’s setUserVisibleHint tied to ViewPager fires outside normal lifecycle, while show/hide doesn’t trigger expected pause/stop. The solution explored is switching to Conductor controllers which give synchronous, predictable transactions, nested controllers, instance-ID routing for onActivityResult, and default retention across rotation (Conductor controllers retain across rotations); it works but requires a container view and has a smaller ecosystem.
AI-written summary · about
chapters (35)
- 0:00Introduction
- 0:49Youve been told lies about fragments
- 1:54Agenda
- 3:04Fragments are bad
- 4:07The number of callbacks
- 4:42A story of an app
- 6:14Whats the problem
- 10:08Commit Now
- 13:05Fragments in XML
- 19:32Lessons learned
- 20:50Refactoring
- 21:37Advantages
- 21:47Custom Views
- 21:59Retaining State
- 22:28Request Permission StartActivityForResult
- 24:07Always use Fragments
- 25:50View Fragments
- 28:04Stop Operation
- 28:19Synchronous Transactions
- 29:55Tricks
- 30:27Conductor
- 31:13Controller Implementation
- 33:10Retain to Instance
- 34:32Override ViewState
- 35:23Demo
- 35:57Animations
- 36:41TargetController
- 40:55ViewPager
- 41:05ViewPager Adapter
- 41:19ViewPagerCallback
- 41:50Disadvantages of Conductor
- 42:13Fragments are easier
- 42:56Userbase is still not even comparable
- 43:38Conclusions
- 45:51Use cases
related talks
30mFragments: What are they good for.
33mFear No Fragments
18mFragments: The good (non-deprecated) parts
37mWhat To Do About Fragments? (en)
46mAndroid Jetpack: How to smartly use fragments in your UI
39mACTIVITIES AND FRAGMENTS ARE NOT MVX VIEWS
31mFragments — As Incredible as It Seems
46mModern Android: How to ditch Activities and Fragments
