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.