Fragments Flashcards
Describe a fragment
● A fragment represents a reusable portion of an app’s UI within an activity.
● A fragment defines and manages its own layout, has its own lifecycle, and can handle its own input events.
Can a fragment live on its own?
● Fragments cannot live on their own, rather, they must be hosted by an activity or another fragment.
● The fragment’s view hierarchy becomes part of, or attaches to, the host’s view hierarchy.
Describe modularity and how fragments ensure it
● Modularity is the extent to which a mobile application may be divided into smaller modules
● Fragments introduce modularity and reusability into your activity’s UI by allowing you
to divide the UI into discrete chunks.
● Fragments can be used to define and manage the UI of a single screen or portion of a screen.
Describe how fragments can be used to modify the app’s appearance at run time
● Dividing a UI into fragments makes it easier to modify an
activity’s appearance at runtime.
● While an activity is in the started lifecycle state or higher,
fragments can be added, replaced, or removed.
How can the changes made to an app’s appearance in during run time be reversed
One can keep a record of these changes in a back stack that is
managed by the activity, allowing the changes to be reversed.
Should there be dependencies between fragments?
● One can use multiple instances of the same fragment class within the same activity, multiple activities, or in child fragments.
● Therefore, fragments only need to have necessary logic for
independent UI management to avoid any dependencies among them.