Reputation: 6500
Im have added a back icon to the action bar,now when i click on that i need to go back to the activity that started it.Is there a actionbar click event which i can hook to and call the this.finish
method
Upvotes: 0
Views: 1725
Reputation: 672
In order to work the home button properly and capture it's action event. You must have to first enabled the home button by calling setHomeButtonEnabled() for targeting android API level 14 onwards.
ActionBar actionBar = getSupportActionBar();
actionBar.setHomeButtonEnabled(true);
Now you've to override the onOptionsItemSelected method inside your activity to capture the home button action of actionbar and also "Back" key on some of the android devices.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish(); // this will dismiss the current activity
}
return true;
}
Upvotes: 3