recently I started using Navigation Component Architecture, now there's a problem I have. in previous fragment transactions we could set tag while transacting to another fragment, how can we do that while using Navigation Component Architecture.
Asked
Active
Viewed 1,365 times
15
-
why you have to set tag, maybe there's another solution for that. I'm saying becasue i didn't find any method to get fragment by tag in Navigations. – Hussnain Haidar Feb 21 '19 at 10:46
-
@HussnainHaidar well I use tag to determined that this fragment is added from which activity. – SinaMN75 Feb 21 '19 at 11:36
-
@SinaMN75 I am also facing the same problem, did you come up with something or any workaround? Basically, I need to call a particular function on a particular fragment. If there is something like finding fragment by tag or name, it will solve the purpose – Abhishek Gupta May 07 '19 at 11:45
-
I'm also having the same issue. If anyone finds a solution to this I'd love to hear it. – Mackalester Aug 07 '20 at 03:45
-
Another one with same problem... – sgm Jan 23 '21 at 22:49
1 Answers
0
Based on FragmentNavigator source-code the target fragment will be instantiate without any option to assigning a tag. So you can't.
But you mentions in comments that:
I use tag to determined that this fragment is added from which activity.
You can use
findNavController().previousBackStackEntry
to get previous stack (who opened this screen) information like its id
, argument
, destination.label
, destination.id
and so on.

beigirad
- 4,986
- 2
- 29
- 52