1

I have a trivial problem with the HomeAsUp Button in My activity, its not being Executing or more concise the Id I'm checking its not the correct one, So I have to Ask, What its The id for the HomeAsUp button on the Toolbar ?

My code:

public boolean onOptionsItemSelected(MenuItem item) {
    log.d("item i "+item.getItemId());
    log.d("Home id "+android.support.v7.appcompat.R.id.home);
    log.d("Home id from R "+R.id.home);
    log.d("Home id from R "+R.id.homeAsUp);
    if (item.getItemId() == R.id.a_profile_menu_item_edit) {
        showProfileEdit();
        return true;
    } else if (item.getItemId() == android.support.v7.appcompat.R.id.home) {
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
}  

And from those logs im printing this is what they printed:

D/Profile[onOptionsItemSelected] - 121﹕ item id 16908332
D/Profile[onOptionsItemSelected] - 122﹕ Home id 2131492868
D/Profile[onOptionsItemSelected] - 123﹕ Home id from R 2131492868
D/Profile[onOptionsItemSelected] - 124﹕ Home id from R 2131492877

So my item.id is 16908332 but neither R.id.home, R.id.homeAsUp, android.support.v7.appcompat.R.id.home are the correct ones, any help is appreciated...

Eefret
  • 4,724
  • 4
  • 30
  • 46
  • Possible duplicate of [Android Up button not working](http://stackoverflow.com/questions/31940056/android-up-button-not-working) – Eefret Mar 22 '16 at 21:14

1 Answers1

2

you need the android.R.id.home with the id 16908332. pay attention to the android in the prefix.

Gilad Levinson
  • 234
  • 2
  • 12