android up button is not working as expected

173 Views Asked by At

I'm followed https://developer.android.com/training/appbar/up-action.html to add an up button for the app bar.

my manifest is

     <activity
        android:name=".activity.MyDiaryAct"
        android:label="@string/title_activity_my_diary"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".activity.PageListAct"
        android:label="@string/title_page_list"
        android:theme="@style/AppTheme.NoActionBar"
        android:parentActivityName=".activity.MyDiaryAct">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="activity.MyDiaryAct" />
    </activity>
    <activity
        android:name=".activity.PageAct"
        android:label="@string/title_page_name"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar"
        android:parentActivityName=".activity.PageListAct" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="activity.PageListAct" />
    </activity>

I started PageAct from MyDiaryAct and click up button. It returned to myDiaryAct but I'm expecting PageListAct.

My codes at PageAct

    android.support.v7.app.ActionBar ab = getSupportActionBar();
    ab.setTitle(page.getName());
    ab.setDisplayHomeAsUpEnabled(true);

What am I missing? I wish not to add codes at onOptionsItemSelected(). Thanks!

PS: I'm using targetSdkVersion 23.

UPDATE: while the possible duplicate post provides useful information and direction to solve my problem but the complete understanding and solution found at here. https://developer.android.com/training/implementing-navigation/ancestral.html

In short, the parent has to be in backs tack else I need to create it manually.

0

There are 0 best solutions below