[Android Studio] Grimspiller:
I have implemented Navigation drawer. But when I open fragment and add back arrow when fragment is open instead "navigation hamburger icon", it doesn't go back to starting page but instead open drawer again. Here is the code I mostly got from tutorial,but want to move on:

MainActivity:

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView=(ListView)findViewById(R.id.listView);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

toolbar=(Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);

//getSupportActionBar().setDisplayShowHomeEnabled(true);
final NavigationDrawerFragment drawerFragment=(NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);

drawerFragment.setUp(R.id.fragment_navigation_drawer,(DrawerLayout)findViewById(R.id.drawer_layout),toolbar);

adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,sports);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItem(position);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mDrawerLayout.closeDrawers();
}
});
}

protected void setFragment(Fragment fragment) {
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction =
fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.drawer_layout, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}

private void selectItem(int position)
{
switch (position) {
case 0:
setFragment(new SoccerFragment());
break;
}
}

and for navigation fragment:

public NavigationDrawerFragment() {
// Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mUserLearnedDrawer=Boolean.valueOf(readFromPreferences(getActivity(), KEY_USER_LEARNED_DRAWER, "false"));
if (savedInstanceState!=null)
{
mFromSavedInstanceState=true;
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
}

public void setUp(int fragmentId,DrawerLayout drawerLayout,Toolbar toolbar) {
//containerView=getActivity().findViewById(fragmentId);
mDrawerLayout=drawerLayout;
mDrawerToggle=new ActionBarDrawerToggle(getActivity(),drawerLayout,toolbar,R.string.drawer_open,R.string.drawer_close)
{
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
if (!mUserLearnedDrawer)
{
mUserLearnedDrawer=true;
saveToPreferences(getActivity(), KEY_USER_LEARNED_DRAWER,mUserLearnedDrawer+"");
}
getActivity().invalidateOptionsMenu();
}

@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
getActivity().invalidateOptionsMenu();
}
};

//if (mUserLearnedDrawer && mFromSavedInstanceState)
//{
// mDrawerLayout.openDrawer(containerView);
//}

mDrawerLayout.setDrawerListener(mDrawerToggle);

mDrawerLayout.post(new Runnable() {
@Override
public void run() {
mDrawerToggle.syncState();
}
});
}

public static void saveToPreferences(Context context,String preferenceName,String preferenceValue)
{
SharedPreferences sharedPreferences=context.getSharedPreferences(PREF_FILE_NAME,Context.MODE_PRIVATE);
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putString(preferenceName, preferenceValue);
editor.apply(); //or commit()
}
public static String readFromPreferences(Context context,String preferenceName,String defaultValue)
{
SharedPreferences sharedPreferences=context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getString(preferenceName,defaultValue);
}
}