Action bar Back button not working

Solution 1:

I solved these problem by adding the below coding in GalleryActivity.

ActionBar actionBar;
actionBar=getActionBar();

actionBar.setDisplayHomeAsUpEnabled(true);

@Override
public boolean onOptionsItemSelected(MenuItem item) { 
        switch (item.getItemId()) {
        case android.R.id.home: 
            onBackPressed();
            return true;
        }

    return super.onOptionsItemSelected(item);
}

In MainActivity:

Previously,

public class HomeActivity extends BaseActivity

Then I change into

public class HomeActivity extends FragmentActivity

In GalleryFragment:

I use Intent to pass it to the GalleryActivity.

@Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        Gallery gallery = (Gallery) arg0.getAdapter().getItem(arg2);

        Intent intent = new Intent(getActivity(), GalleryActivity.class);
        intent.putExtra("position", position);
        intent.putExtra("id", gallery.getGalId());
        intent.putExtra("name", gallery.getAlbumTitle());
        startActivity(intent);

        // mCallback.OnGalItemSelected(gallery.getGalId(),gallery.getAlbumTitle());
    } 

Solution 2:

Please read this

you should have something like this:

    <activity
        android:name="com.sit.fth.activity.HomeActivity"
        android:screenOrientation="portrait">

    </activity>
    <activity
        android:name="com.sit.fth.activity.GalleryActivity"
        android:screenOrientation="portrait"
        android:parentActivityName="com.sit.fth.activity.HomeActivity">

    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value="com.sit.fth.activity.HomeActivity"/>

   </activity>


then calling NavUtils.navigateUpFromSameTask(this) will cause navigating to parent activity (HomeActivity).