manulorenzo manulorenzo - 1 year ago 86
Android Question

Action Bar's onClick listener for the Home button

How can I implement a custom

for the Home button of the Action Bar?

I already did a
and now I want to redirect the user to a certain activity in case the Home button is clicked.

I tried with:

public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
item.setOnMenuItemClickListener(new OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
Intent i = new Intent();
i.setClass(BestemmingActivity.this, StartActivity.class);
return true;
return super.onOptionsItemSelected(item);

but it never enters in the

Basically, it's done just like in this link but still it doesn't enter in the listener.

Answer Source

Fixed: no need to use a setOnMenuItemClickListener. Just pressing the button, it creates and launches the activity through the intent.

Thanks a lot everybody for your help!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download