FragmentTransaction is not allowed to be added to back stack?

前端 未结 4 1980
迷失自我
迷失自我 2021-01-22 21:18

why cant my fragments be added to back stack?

@Override
    public void onTabSelected(Tab tab, android.app.FragmentTransaction ft) {
        FragmentTransaction          


        
4条回答
  •  遥遥无期
    2021-01-22 22:12

    You are using Action Bar tabs and you want the Fragments bound to the tabs to be added to the back stack, usually that is forbidden (and it is understandable inmost cases). Action Bar Tabs are not allowed to be added to the Back Stack. If your application is tab based it is ok, but if you display tabs only in particular situations and in others you hide them this behavior is not good (and I do not understand why Google does not let it).....maybe you need the first tab to be added to the back stack (my situation), but in such a case onTabSelected will not allow you to add the transaction to the back stack, it will throw an exception because the addToBackStack is blocked inside this method call (there is the method disallowAddToBackStack inside FragmentTransaction that does exactly that...I totally disagree with that constraint).

提交回复
热议问题