How can I implement a custom onClickListener for the home button of the action bar?
I already did getSupportActionBar().setDisplayHomeAsUpEnabled(true); , and now I want to redirect the user to a certain activity in case of pressing the "Home" button.
I tried:
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: item.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { Intent i = new Intent(); i.setClass(BestemmingActivity.this, StartActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); return true; } }); default: return super.onOptionsItemSelected(item); } }
but it never enters onMenuItemClick .
In principle, this is done in the same way as in this link , but still it is not included in the listener.
android android-intent actionbarsherlock onitemclicklistener
manulorenzo Jun 18 2018-12-12T00: 00Z
source share