Dynamically managing fragments
The process of dynamically managing fragments commonly involves multiple steps. The steps may be simple like removing one fragment and adding another, or they may be more complex, involving the removal and addition of multiple fragments. In any case, we need to be certain that all dynamic changes to the fragments within an activity that constitute a shift from one application screen to the next occur together as a single unit of work. Android does this by grouping the steps into transactions using the FragmentTransaction
class.
Conceptually, the FragmentTransaction
class behaves in a manner consistent with other transaction models: start the transaction, identify the desired changes, and commit the transaction once all changes within that unit of work are identified.
When we're ready to make changes, we start a new FragmentTransaction
instance by calling the beginTransaction
method on the activity's FragmentManager
instance, which returns back a reference to...