Steven Schoen Steven Schoen - 1 year ago 94
Android Question

Proper way to handle action bar up button?

I use ActionBarSherlock (although I don't think it matters).

I have a Main activity and an About activity. I want the About activity to show the back-arrow by its logo, and do the proper animation and such.
I don't know how to do this properly.

Currently, I have under onOptionsMenuItemSelected to launch the Main activity when the Up/Home button is pressed, but it's hacky and doesn't really work right. It plays the wrong animation, and handles multitasking poorly.

How do I set this up right?

Here's the part in my Main activity that launches the About:

Intent aboutIntent = new Intent(MainActivity.this, About.class);

Here's my About activity:

package com.stevenschoen.test;

import android.content.Intent;
import android.os.Bundle;

import com.actionbarsherlock.view.MenuItem;

public class About extends SherlockActivity {
public void onCreate(Bundle savedInstanceState) {


public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {

// app icon in action bar clicked; go home
Intent intentHome = new Intent(this, MainActivity.class);
return true;

return super.onOptionsItemSelected(item);

Answer Source

Found out the root of my problem was a change in the manifest I made a while ago: I added this line:


so my main activity wouldn't be relaunched. Changing it to:


solved my problems, and I was able to remove all the onOptionsItemSelected stuff. I knew there was something wrong, that Android should have been able to handle this better, and I was right. Check the manifest :P

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