Separate Back Stack for each tab in Android using Fragments

后端 未结 12 1012
南旧
南旧 2020-11-22 14:51

I\'m trying to implement tabs for navigation in an Android app. Since TabActivity and ActivityGroup are deprecated I would like to implement it using Fragments instead.

12条回答
  •  遥遥无期
    2020-11-22 15:18

    The framework won't currently do this for you automatically. You will need to build and manage your own back stacks for each tab.

    To be honest, this seems like a really questionable thing to do. I can't imagine it resulting in a decent UI -- if the back key is going to do different things depending on the tab I am, especially if the back key also has its normal behavior of closing the entire activity when at the top of the stack... sounds nasty.

    If you are trying to build something like a web browser UI, to get a UX that is natural to the user is going to involve a lot of subtle tweaks of behavior depending on context, so you'll definitely need to do your own back stack management rather than rely on some default implementation in the framework. For an example try paying attention to how the back key interacts with the standard browser in the various ways you can go in and out of it. (Each "window" in the browser is essentially a tab.)

提交回复
热议问题