Up Navigation - Return to launching activity

26 Views Asked by At

I have an activity up-navigation enabled, so I have the android:parentActivityName set. This works.

However, I want my AppPreferencesActivity to be accessed from different parent activities. I'd like to have my up-action return to the activity that launched it. Removing the parentActivityName attribute removes the up action completely.

How can I configure the application so that Up Navigation returns me to the activity that launched my AppPreferencesActivity?

<activity
        android:name="org.me.AppPreferencesActivity"
        android:label="@string/title_activity_preferences"
        android:parentActivityName="org.me.MainActivity">
</activity>
1

There are 1 best solutions below

0
Stealth Rabbi On

First, I removed the parentActivityNameAttribute.

Then, in my AppPrefernecesActivity, I added this to the creation portion:

getActionBar().setDisplayHomeAsUpEnabled(true);

THen, defined a case for handling the "home" action.

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
    switch (item.getItemId())
    {
        case android.R.id.home:
            finish();
            return true;
        default:
            return false;
    }
}

This works, but is there a better way? This seems a bit hackish.