0

I have this button on the topmost left part. And for some reason it is not going back to it's previous page when I click it. I've checked the other links already but it is not working.

the one on the top left button

The activity code on that one

public class CardListActivity extends Activity  {
    private static final String LOG_TAG = CardListActivity.class.getSimpleName();
    private EventBus eventBus;
    private Activity activity;
    private CardListRequest cardListRequest;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    init();

}

public void init() {
    Log.e(LOG_TAG, "XXXX Start : init XXXX");
    setUpActionBar();
    activity = this;
    setContentView(R.layout.activity_card_list);


    Log.e(LOG_TAG, "XXXX Finish : init XXXX");
}

private void setUpActionBar() {
    getActionBar().setTitle(CardListActivity.class.getSimpleName());
    getActionBar().setDisplayHomeAsUpEnabled(true);
}


}

AndroidManifest.xml

...

    <activity
        android:name=".CardListActivity"
        android:label="@string/title_activity_card_list"
        android:parentActivityName=".HomeActivity2">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.pw.mccdealsapp.HomeActivity2" />
    </activity>

...

2 Answers 2

1

This page contains all the information to create an Up button that works correctly.

You need to add, in your activity, something like:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            NavUtils.navigateUpFromSameTask(this);
            return true;
     }
     return super.onOptionsItemSelected(item);
}
2
  • Thanks @Andrea Basso. Oct 21, 2015 at 2:29
  • @PaulaKristin You're welcome :) If the answer works fine, please accept it
    – Andrea
    Oct 21, 2015 at 11:05
1

first on your onCreate method put this

//action bar back icon
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

then override this method and make back opetion go to its parent

public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home){
            finish();
        }
        return super.onOptionsItemSelected(item);
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.