title: Exiting from Activity with only fragments
body: <p>My app contains one empty activity and a couple of fragments. The <code>onCreate</code> of the activity replaces the empty view in <code>activity_main.xml</code> with a <code>MainFragment</code> that contains some buttons. Each button launches a separate fragment, and user can navigate from one fragment to another, etc.</p>
  
  <p>On the press of back key, the current fragment correctly gets replaced with the previous fragment, until you get to the <code>MainFragment</code>. When user presses back from <code>MainFragment</code>, it hides the main fragment and you see the white empty background of the main activity. But I want to exit from the activity at this point, as that would be the sensible behaviour.</p>
  
  <p>I am able to achieve this by calling super.onBackPressed() for a second time from onBackPressed if there are no fragments left in the fragment manager.</p>
  
  <pre><code>@Override
  public void onBackPressed() {
      super.onBackPressed();
      FragmentManager manager = getSupportFragmentManager();
      List&lt;Fragment&gt; fragments = manager.getFragments();
      if (fragments == null || fragments.size() == 0) {
          Log.d(TAG, "No more fragments: exit");
          super.onBackPressed();
      }
  }
  </code></pre>
  
  <p>Is this acceptable thing to do - would it create any issues in the activity workflow? Is there a better/standard way to handle this scenario?</p>