1

I've been working on an app with multiple ActionBar activities, and from the outset the HomeAsUp button has been visible and working on all of the activities selected from the MainActivity. Today I noticed that it is no longer there - but I can't figure out what I have changed that would affect it.

The most significant change in recent days is that I migrated the project from Eclipse to Android Studio because I was having problems with Eclipse frequently corrupting my project files and requiring a complete reinstall.

This is a sample of the code in the main activity which creates the new activities:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  Intent intent=null;
  int id = item.getItemId();
  switch (id) {
    case R.id.action_list:
      intent = new Intent(this, StudyListActivity.class);
      break;
    // etc
  }

  if (intent != null) {
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
    return true;
  }
  return super.onOptionsItemSelected(item);
}

Here is the declaration of the intent in the manifest

<activity
  android:name="com.example.app.StudyListActivity"
  android:label="@string/activity_list"

  android:parentActivityName="com.example.app.MainActivity" >
    <meta-data
      android:name="android.support.PARENT_ACTIVITY"
      android:value="com.example.app.MainActivity" />
</activity>

since it stopped working I have also tried putting

getSupportActionBar().setHomeButtonEnabled(true);

in the onCreate method of the called activity (as per Display back button on action bar) but that makes no difference.

So I'm wondering if there is anything that got stripped out in my migration from eclipse which is preventing it showing (or something else I could have changed which might inadvertently have disabled it)

Community
  • 1
  • 1
QuantumTiger
  • 970
  • 1
  • 10
  • 22

2 Answers2

2

you should enable it via setDisplayOptions

getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME);
Panther
  • 8,938
  • 3
  • 23
  • 34
1

You could also try

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

In the activity you want the HomeAsUp icon in