Rajarshi
Rajarshi

Reputation: 2509

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?

Upvotes: 4

Views: 414

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 199795

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.

Upvotes: 4

Related Questions