I'm trying to debug some code and was hoping to list the fragments in the current backstack in Android. The stock solution is to simply list them from the support manager, so from a method within an activity :
Log.i("fragments","Count : " + supportFragmentManager.fragments.toString())
However using this along with Android's navigation component simply lists the navigation host fragment.
... I/fragments: [NavHostFragment{b1a2d20 (f8ec2420-b534-42df-89f0-0cb189610a26) id=0x7f080001}]
Some of the answers on SO e.g. Sergii Suvorov provide the following alternative :
Log.i("fragments","Count : " + supportFragmentManager.findFragmentById(R.id.NAVIGATION)?.childFragmentManager?.fragments.toString())
Which simply returns null for me
... I/fragments: null
Within a method of a fragment I can call the following
Log.i("fragments", fragmentManager?.fragments.toString())
and it does return the desired result
... I/fragments: [FirstFragment{1475645 (3bb8566b-22b0-4c98-82ea-566e18915145) id=0x7f080001}]
I do not however see how to do this from the activity, perhaps some one out there knows the magic incantation ?
N
or so items upon it's own backstack by comparison. – RoleyfindNavigationController
does not appear to have an attribute that would return a backstack of sorts from what I can see and the "sergei" method returnsnull
for me. – Roley