In order to reuse some fragments in my app, I need to know which Fragment is the second on the back stack.
In order to do that I'm using getFragmentManager().getFragments()
, which shows the following error (but works!)
FragmentManager.getFragments can only be called from within the same library group (groupId=com.android.support)
Is it safe to use? Could I get the same result by another approach?
Here is the code:
public Fragment getCallerFragment(){
List<Fragment> fragments = getFragmentManager().getFragments();
return fragments.get(fragments.size()-2);
}