문제

I'm trying to make the UP button provide back navigation to a specific fragment in the parent activity.

Activity1 contatins FragmentA and FragmentB. You can launch Activity2 from FragmentB.

Activity1 is declared as the parent of Activity2 in the Manifest file.

<activity
        android:name="com.example.Activity2"
        android:parentActivityName="com.example.Activity1" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.Activity1" />
</activity>

When you're in Activity2 and press UP button, I want you to return to FragmentB in Activity1. Instead, it returns to FragmentA (because it's the default fragment in Activity1).

Thank you in advance.

도움이 되었습니까?

해결책

I suppose that you finish Activity A when you launch Activity B, otherwise you would still have the fragment B visible int the Activity A (as you left it). But try to put an extra in the intent of the Activity B that launches the Activity A that says which fragment should be active in that Activity. That way, when the Activity A is created, you can check the bundle, check if there is any information about which fragment should be visible, and, if so, set the fragment as visible.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top