title: Correct way to close fragments
body: <p>There're two parts to this question.</p>
  
  <p>Suppose we have an Activity and then two fragments: a ListFragment and a Fragment (which will be shown when you click an item from the ListFragment).</p>
  
  <p><strong>Part 1</strong></p>
  
  <p>Where should I close the fragment? By this I mean what would be considered good from a design point of view. I see two options: one declaring an interface in the fragment and having the activity implementing it, let's call it closeFragment(). This would be a way to communicate from the fragment to the activity like shown in the Dev Site. The other one is probably quite simple and is calling getActivity().getSupportFragmentManager() and using the manager to close it.</p>
  
  <p><strong>Part 2</strong></p>
  
  <p>I know how to create a fragment and replace it since it's on the Dev site but I have doubts about closing one. How should I actually close it? Is something like the following code correct? Suppose that the fragment was added to the BackStack.</p>
  
  <pre><code>FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
  getSupportFragmentManager().popBackStack();
  transaction.remove(this);
  transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
  transaction.commit();
  </code></pre>
  
  <p>Thank you very much.</p>