My app is Activity based and has several levels, i.e. ActivityA has actions to start ActivityB, which in turn starts ActivityC. Pressing 'back' from ActivityC returns to ActivtyB, and going back from that returns to ActivityA, as you would expect.
In my ActionBar I've enabled the Home icon, so that it displays the Up navigation arrow. I intended it to work in the same way as the Back button, but clicking Up from ActivityC still returns me to ActivityA, even though I've added the following to the manifest:
<activity android:name=".activity.ActivityC"
android:parentActivityName=".activity.ActivityB">
<!-- Parent activity meta-data to support API level 7+ -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.ActivityB" />
</activity>
Two questions:
1) Am I trying to misuse the ActionBar here? Should the Up icon always return you to the main activity? 2) Why is my implementation not working as I intended?
1) No, you are not trying to misuse the ActionBar here. If you are going from A -> B -> C then pressing Up from C should take you to B and NOT A. This is mentioned here as
2)Your implementation is not working as intended because you forgot to do the following as mentioned here:
I however do not recommend that you use the above technique to handle your Up Navigation as the above method will not work for ICS and below. The reason it won't work is because NavUtils behaves differently for Pre JellyBean and Post JellyBean as explained in this SO.
A better way is to do this is to handle the Up action manually in the Child Activity:
And best part of this manual approach is that it works for ALL Api Levels.