2

I have an application with one activity and many fragments that work on tablets with Android 4.0 and user support.library.v4

The first screen shows two fragments A and B:

----------------------------------
A      | B   <view pager>
       |------------------------
<list  |
view>  |
       |     <view pager>
       |
----------------------------------

After click on A item I add a new fragment A with add to back stask for current fragment A. I show a new fragments A1, C - C includes nested fragments D and E are added via replace(, D, ) without adding to backstak

----------------------------------
A1     |             C
       |
<list  |    D      |     E
view>  |           |
       |           |
       |           |
----------------------------------

The issue occurs when I start working on back behaviour. I start use getShildFragmentManager() for my adapter in fragment B so back start show a previous screen but after multiple clicks between this fragments: A -> A1, C(D,E) -> BACK -> A -> A1, C(D,E) -> BACK -> A -> A1, C(D,E) -> BACK -> [ISSUE] I see a fragment A but don't see a fragment B sometimes is just background from previous fragment D and E

Could you tell me where is my issue?

ADDITIONAL INFO 1) I set layout with two framelayout-containers for fragments A and B 2) A is list fragment 3) user click on item of A 4) A is replaced by new A instance and A is added in backstak; B is replaced by new fragment C that has layout with two framelayout containers for D and E fragments 5) User click on A instance and C shows D and E fragments via repalce and don't add this transaction into backstack 6) User click BACK 7) return to step 1)

4

1 回答 1

1

所以过了一段时间我找到了解决方案:

  1. 使用嵌套在其他片段中的片段时使用 ChildFragmentManger
  2. 在 onPause() 之后不要使用任何片段事务(您可以使用 commitStateLoss(),但它并不能解决所有问题,并且出于多种原因不鼓励)
  3. 跟踪您孩子的片段,不要忘记将它们从后台删除或重复使用
于 2013-09-14T08:44:52.597 回答