title: Android activity/fragment responsibilities for data loading
body: <p>When starting a new application for a client, I am asking myself again the same question about who should be responsible for loading data: activities or fragments. I have taken both options for various apps and I was wondering which pattern is best according to you in terms of:</p>
  
  <ul>
  <li>limiting the code complexity.</li>
  <li>handling edge cases (like screen rotation, screen going power save, loss of connectivity, etc.)</li>
  </ul>
  
  <h3>Option 1 - Activity loads data &amp; fragment only displays it</h3>
  
  <p>This allows to have fragments that are just fed a bunch of objects to display. They know nothing about loading data and how we load that.</p>
  
  <p>On the other side, the activity loads data using whichever method is required (for instance initially the latest 50 entries and on a search, loads the search result). It then passes it to the fragment which displays it. Method to load the data could be anything (from service, from DB, ... fragments only know about POJOs)</p>
  
  <p>It's kind of a MVC architecture where the activity is the controller and fragments are the view.</p>
  
  <h3>Option 2 - Activity arranges fragments &amp; fragments are responsible to fetch the data</h3>
  
  <p>In this pattern, fragments are autonomous pieces of application. They know how to load the data they are displaying and how to show it to the user.</p>
  
  <p>Activities are simply a way to arrange fragments on screen and to coordinate transitions between application activities. </p>