Inside your SettingsActivity
you need to override onOptionsItemSelected
to enable the back button on top left corner of Action Bar for going back. It does not know by itself that what it needs to do on click. Inside the case android.R.id.home
you can just call finish()
. This will finish your current activity and you will go back to MainActivity
which started it. Eg:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
return true;
}
return super.onOptionsItemSelected(item);
}
Just for completeness, to enable the home button, you may add the following in your onCreate()
of SettingsActivity
:
getActionBar().setDisplayHomeAsUpEnabled(true);
As per docs of setDisplayHomeAsUpEnabled()
It is to show the user that selecting home will return one level up rather than to the top level of the app.
Hope this helps.