The process of dynamically managing fragments commonly involves multiple steps. The steps may be as simple as 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.
Commit the transaction once all changes within this unit of work are identified.
When we're ready to make changes, we will start a new FragmentTransaction
instance by calling the beginTransaction
method on the activity's FragmentManager
instance, which returns a reference to the FragmentTransaction...