I have a SearchAcvitity which has a child PersonActivity. Each are FragmentActivity's. Here's my manifest file:
<activity android:name=".SearchActivity" android:label="@string/search_title">
</activity>
<activity android:name=".PersonActivity" android:label="@string/person_title"
android:parentActivityName=".SearchActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".SearchActivity" />
</activity>
From SearchFragment, I start PersonActivity like so:
Intent i = new Intent(getActivity(), PersonActivity.class);
startActivity(i);
This alone adds the left-facing caret alongside the app icon in PersonFragment. When I press this icon, it recreates SearchAcvitiy (and fragment), so its previous state is lost.
When I instead press the back button from PersonFragment, it goes back to SearchActivity's SearchFragment via onResume(...) and its state is intact. How can I make this happen with the up action?
Please note that I don't make this call in PersonFragment:
getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
UP navigation launches the parent Activity with Intent.FLAG_ACTIVITY_CLEAR_TOP
. The standard behaviour of this flag is to finish all Activities that are on top of the parent Activity in the task stack including the parent Activity itself and then launch a new instance of the parent Activity**. If you want to resume the existing instance of the parent Activity, then you can set the following in the manifest for the parent Activity:
android:launchMode="singleTop"
When CLEAR_TOP and SINGLE_TOP are used together, this will resume an existing instance of the parent Activity. In this case, onCreate()
will not be called on the resumed parent Activity, but instead onNewIntent()
will be called instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With