title: Android Up button not working
body: <p>I am trying to manually implement the actions that must take place when the up button on the actionbar is pressed but for some reason nothing happens when I press it.</p>
  
  <p>here is my code:</p>
  
  <pre><code>public class ActivityOne extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_activity_one);
          Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar_actionbar);
          setSupportActionBar(toolbar);
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
          Button button = (Button)findViewById(R.id.btn1);
          button.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  openActivityTwo();
              }
          });
          Button button2 = (Button)findViewById(R.id.btn2);
          button2.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  openActivityThree();
              }
          });
      }
  
  
      void openActivityTwo(){
          Intent intent = new Intent(this, ActivityTwo.class);
          startActivity(intent);
      }
  
      void openActivityThree(){
          Intent intent = new Intent(this, ActivityThree.class);
          startActivity(intent);
      }
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_activity_one, menu);
          return true;
      }
  
      @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;
          }
  
          else if(id == R.id.homeAsUp){
              Log.i("","Up is pressed");
              finish();
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  
  <p>I understand that I have to explicitly assign a parent activity for the activity <strong>I want to implement up navigation on the manifest file</strong>, but problem is that this activity has multiple parents so I thought calling the <code>finish()</code> method when the up button is pressed on this activity will be the better approach.</p>
  
  <p>I have already tried both <code>id == R.id.home</code> and <code>id ==  R.id.homeAsUp</code> and they both do not work. I do not know if it is because I am using <code>AppCompactActivity</code> or what Please help</p>