get the latest fragment in backstack

后端 未结 17 2058
长发绾君心
长发绾君心 2020-11-27 11:24

How can I get the latest fragment instance added in backstack (if I do not know the fragment tag & id)?

FragmentManager fragManager = activity.getSupport         


        
17条回答
  •  孤城傲影
    2020-11-27 11:48

    you can use getBackStackEntryAt(). In order to know how many entry the activity holds in the backstack you can use getBackStackEntryCount()

    int lastFragmentCount = getBackStackEntryCount() - 1;
    

提交回复
热议问题