Fragment manager

The component that is responsible for interacting with fragments from your current activity is fragment manager. We can use the FragmentManager form in two different imports:


Import from the Android support library is recommended.

To perform a series of edit operations, start the fragment transaction using the beginTransaction() method. It will return an instance of transaction. To add a fragment (usually the first), use the add method, like in our example. The method takes the same arguments, but replaces the current fragment if already added. If we are planning to navigate backwards through fragments, it is needed to add the transaction to back stack by using ...

Get Mastering Android Development with Kotlin now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.