Ömer ASLAN
Ömer ASLAN

Reputation: 139

How can I return Base Activity

I am creating new Application in Android Platform.

I'm Having trouble with returning the base Activity.

public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        setContentView(R.layout.setting_layout);
         ActionBar actionBar = getSupportActionBar();
         //Return to Base
         actionBar.setDisplayHomeAsUpEnabled(true);

    }
    return super.onOptionsItemSelected(item);
}

I tried to change Manifest.xml with:

<application 
    android:launchMode="singleTask"
<activity...
<meta-data android:name="android.support.PARENT_ACTIVITY"
    android:value=".TestParentActivity">
</meta-data>
</activity>

etc..

However, these don't work.

Please help me.

Thank You. Best Regards.

Upvotes: 1

Views: 187

Answers (2)

tyczj
tyczj

Reputation: 73916

the up button id is android.R.id.home

so in your onOptionsItemSelected you need this

case android.R.id.home:
    NavUtils.navigateUpFromSameTask(this);
    return true;

and in the activity in your manifest you need to declare a parent activity tag

android:parentActivityName

Upvotes: 0

AnkitSomani
AnkitSomani

Reputation: 1192

Try using android:ParentActivityName:".MainActivity" in your tag

Beginning in Android 4.1 (API level 16), you can declare the logical parent of each activity by specifying the android:parentActivityName attribute in the element.

If your app supports Android 4.0 and lower, include the Support Library with your app and add a element inside the . Then specify the parent activity as the value for android.support.PARENT_ACTIVITY, matching the android:parentActivityName attribute.

<activity
    android:name="com.example.myfirstapp.DisplayMessageActivity"
    android:label="@string/title_activity_display_message"
    android:parentActivityName="com.example.myfirstapp.MainActivity" >
    <!-- Parent activity meta-data to support 4.0 and lower -->
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value="com.example.myfirstapp.MainActivity" />
</activity>

For more details about the ActionBar Naviagation read here

Upvotes: 1

Related Questions