0
votes

I have one Activity and three Fragments. When I go from one fragment to another I write it transaction into backStack:

transaction.addToBackStack(null);

When I press back arrow on ActionBar and go to the first fragment that arrow is lose and it's right.

 switch (item.getItemId()) {
        case android.R.id.home:

           FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            OfficialNameFragment offName = new OfficialNameFragment();
            fragmentTransaction.remove(offName);
            fragmentTransaction.commit();
            getFragmentManager().popBackStack();

((AppCompatActivity)getActivity()).getSupportActionBar() .setDisplayHomeAsUpEnabled(false);

            return true;

        default:
            return super.onOptionsItemSelected(item);
    }

But if I press system back button and go to the first fragment that back arrow is stay and it's wrong.

1

1 Answers

0
votes

when I override system back button in Activity like that

@Override
public void onBackPressed(){
    super.onBackPressed();
    getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}

back arrow is lose when I go from third to second fragments. But it is necessary that the arrow disappears when the transition from the second to the first fragment.