title: ActionBar Home button - hide fragment and clear back stack
body: <p>I would like to implement Home/Up button in the <code>actionBar</code>. I have simple application with one Activity (<strong>A</strong>) and two fragments (Settings (<strong>B</strong>) and About (<strong>C</strong>)).</p>
  
  <p>In the other questions I have found to use <code>popBackStack</code>, but that's not the solution bacause if user goes A > B > C > B > C, back-button goes C > B > C > B > A (is this correct behaviour?).</p>
  
  <pre><code>    switch (item.getItemId()){
          case R.id.action_settings:
              // get preferences fragment
              getFragmentManager().beginTransaction()
                      .replace(android.R.id.content, new PrefFragment())
                      .addToBackStack(null)
                      .commit();
              getSupportActionBar().setDisplayHomeAsUpEnabled(true);
              return true;
          case R.id.action_about:
              // get about fragment
              getFragmentManager().beginTransaction()
                      .replace(android.R.id.content, new AboutFragment())
                      .addToBackStack(null)
                      .commit();
              getSupportActionBar().setDisplayHomeAsUpEnabled(true);
              return true;
          case android.R.id.home:
              // clear back stack and show home screen?
  
              getSupportActionBar().setDisplayHomeAsUpEnabled(false);
              return true;
      }
  </code></pre>
  
  <p>I would need last case to hide any fragment (show main activity window) and clear my back stack - go home, not back. How could I achieve that?</p>
  
  <p>I use AppCompat library.</p>