Context: Very familiar with iOS development and Java. New to Android.
Problem: I added a handler to navigate 'back' when the home button is pressed. It works fine, until I add another handler when the user scan button:
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
if (item.getItemId() == R.id.home) //The ID here is no longer R.id.home
{
navigateBack();
return true;
}
else if (item.getItemId() == R.id.scan_button)
{
presentScanner();
return true;
}
return super.onOptionsItemSelected(item);
}
As soon as I add the code for the Scan the id is no longer R.id.home. It works if I do this:
if (item.getItemId() == 16908332)
{ . . etc. . .
What has happened? How can I correctly get the ID of the home button in this current activity?
Update: Changed from R.id.home to 'android.R.id.home' and this works. Why?