![]() ![]() When the user (now on B) taps the back button, the transaction gets reversed and since the FM thinks he removed C in favor of B, it is going to flip that removing B and in favor of C ( instead of A) which is getting re-added to the FragmentManager fragments list. Hence the first and only occurrence here would be “ C“. Now when the user is in the “A,C” situation this happens.Ĭan you guess what will the result of line 11 be? Internally, the FragmentManager implementations iterates over a list and stops at the first occurrence of a fragment having such id. Now remember, “ A” was added, removed. When the user is the first time in “C” the above mentioned list is composed by “A”, “B”, “C” (As expected), but when the user goes back (generating the A,C both showing) the transaction that is being reversed is “remove B and re-add A” hence these 2 fragments are removed by the list leaving “C” alone as first element. Why? Lets debug the previous sentence a bit more. But “C” comes before than “A” in this internal list. When A & C overlaps they both have the same id (R.id.content) and they’re both in FragmentManager “added” list. ![]() ![]() The result will be C while the user might expect to get back to “A” (As it should!). Lets see the full navigation path to get this: “A” -> “B” -> “C” -> (back) -> shown -> B -> (back) -> C! But you will see a strange behavior when the user tries again to go from A to B (again) and then pressed back. You might even not see this if your fragment root view has an android:background property ( possible overdraw?). ![]() The results? We’ve both aFragment and cFragment showing on the screen! NICE □ The reversed transaction tries to remove “ B” from R.id.content (which is not there cause we’ve “ C“) and adds “ A” back. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |