Sorry, looking at get the latest fragment in backstack I understood that findFragmentByTag(tag)
finds the last fragment with required tag
. In my case after adding many fragments it sometimes found not last fragment with tag
, but a previous to last (with the same tag
). Maybe there is a bug in my code, I don't know, why is that.
First I tried to use callbacks, then tried to use parentFragment
and childFragmentManager
, see getParentFragment returning null. In fragment D
I called parentFragment
and accessed to methods of A
and could update the last A
fragment. This solution has two problems.
1) Child fragment (D
) inherits a toolbar from parent (A
) and adds own buttons. And after clicking Back
button we return not to a parent, but even quit parent (A
).
2) If we want to update not previous fragment (so that between A and D are also 3 fragments), it seems to be impossible.
So, I cancelled that solution and changed the application behaviour. I clear a backstack where it is possible. So that we cannot have two A
fragments in backstack. I use supportFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE)
. Yes, that's a workaround, but I don't know, how to deal with that bug.