I read this tutorial here - http://developer.android.com/training/implementing-navigation/ancestral.html - for implementing Up Navigation. Similar to the way the user presses the "Back" button on the phone, but the onBackPressed () method does not work when the "Up" button is pressed. In the tutorial, they show that you catch R.id.home in the onOptionsItemSelected () method. This web page - http://developer.android.com/reference/android/R.id.html - shows that the value of R.id.home should be 16908332, but that is not in my application. In the code below, if I use R.id.home, it fails. If I program hard in 16908332, it works. For me, R.id.home is evaluated to 21312330724. According to the page, all R.id values ββstart at 1690. I hate hardcoding in the value for the built-in value, but I'm not sure what else to do. Could this cause problems in the future? Am I doing something wrong? This is mistake?
Greg
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } //noinspection SimplifiableIfStatement if (id == R.id.home) {//16908332 Intent upIntent = NavUtils.getParentActivityIntent(this); upIntent.putExtra(CAT_ID, CatID); upIntent.putExtra(USER_ID, UserID); upIntent.putExtra(LIST_ID, ListID); setResult(RESULT_OK, upIntent); NavUtils.navigateUpTo(this, upIntent); return true; } return super.onOptionsItemSelected(item); }
source share