Situation *************: I'm looking some intel about the onKey override method by fragment. I have single activity several fragment structure. Only one fragment visible at time. I show a new fragment with a transaction add fragment ( because I don't want recreate the previous fragment when back so I don't use replace) + setPrimaryFragment each time for the top fragement. I go back with transaction remove fragment + setPrimaryFragment to update with the top fragment. On my fragment, I override onKey method.
Now my problem ************* Sometimes the onKey (back button) is not received by the top fragment (visible and primary) but received by fragment not visible and not primary.
case 1: With 2 fragments, open and back, works fine.
with 3 fragments, open fr1, open fr2, open fr3 and back to fr2(remove and destroy fr3). So now if I push back again, onKey is not call on the second fragement fr2 (visible and primary) but by the first fragment fr1 (not visible and not primary).
Is there someone can tell me why? How the onKey decide which fragment to call ?
For now, I solve this by checking inside onKey if the fragement is primary, if not I dispatch myself the call to the primary. But I still want to understand why...
Thanks.