Ronak Vala
Ronak Vala

Reputation: 23

android default Back button minimizes the application after I implement code for action bar back button

I have implemented code for action bar button and it works fine but after that my smart phone back button is closes or minimizes when I press it. Here is my Code

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_about);

    /**
     * Action Bar Back Button
     */
    getActionBar().setDisplayHomeAsUpEnabled(true);
}

@Override
   public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
         // Respond to the action bar's Up/Home button
         case android.R.id.home:
         NavUtils.navigateUpFromSameTask(this);
         return true;
      }
      return super.onOptionsItemSelected(item);
   }
   @Override
   public void onBackPressed() {
      moveTaskToBack(true); 
      AboutActivity.this.finish();
   }

Upvotes: 0

Views: 1308

Answers (1)

Badrul
Badrul

Reputation: 1642

public void onBackPressed() {
  moveTaskToBack(true); 
  AboutActivity.this.finish();// you are finishing the activity
}

if you want to go back try this

@Override
public void onBackPressed()
{
     // code here to show dialog
     super.onBackPressed();  // optional depending on your needs
}

Upvotes: 1

Related Questions