Sobes.tech
Junior — Middle

Have you used alternative methods for managing fragments besides FragmentManager?

sobes.tech AI

Answer from AI

Yes, besides the standard FragmentManager, in Android, alternative ways to manage fragments can be used:

  • Navigation Component — a modern tool from Android Jetpack that simplifies navigation and fragment management through NavController and navigation graphs.
  • ViewPager2 — for managing a set of fragments with swipe functionality.
  • FragmentContainerView — a container for fragments that integrates better with the Navigation Component.

Example of using the Navigation Component:

val navController = findNavController(R.id.nav_host_fragment)
navController.navigate(R.id.action_firstFragment_to_secondFragment)

This allows abstracting from direct calls to FragmentManager and managing navigation declaratively.