Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation Components and Headless Fragment

Suppose, using Navigation Architecture Components, I'm within a fragment, Fragment_A, and want to do a small task using a Headless fragment. My questions are:

  1. How to properly/correct way to add a headless fragment from within Fragment_A?

  2. How to detect that I'm navigating out from Fragment_A, that started the headless fragment so that I can remove the headless fragment?

like image 934
Rajarshi Avatar asked Oct 20 '25 05:10

Rajarshi


1 Answers

You can add a headless fragment by using getChildFragmentManager() and doing a normal FragmentTransaction. The benefit of using the child FragmentManager is that all of the child fragments are removed when the parent is removed.

like image 66
ianhanniballake Avatar answered Oct 21 '25 19:10

ianhanniballake