Fragments, and What You Have Seen Already
Fragments can do most everything of what we have seen so far that activities can do:
- Fragments can use layout resources to show a UI
- Fragments can have a
ViewModel— in fact, they can not only have their own, but they can share aViewModelwith the activity that hosts them - Fragments have lifecycle methods, including both ones that you see in activities (e.g.,
onCreate()andonDestroy()) and ones that are distinct for fragments (e.g.,onAttach()andonDetach())
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.