title: Android: Handling synchronous network calls
body: <p>I have an android library that makes a significant amount of synchronous network calls, I intend to use this library in my app. For example, when the app launches I need to display a list of users, a list of usergroups and general info. For this I already have a main activity which holds three fragments(two listfragments for the list and one normal fragment) for the three things to display, the data for the user list and list of usergroups are from synchronous network calls in the library mentioned earlier.  My question is, what is the proper(recommended) way to use these synchronous library calls to fetch the data to be displayed by the fragments. From my understanding there are 3 major ways of doing this.</p>
  
  <ol>
  <li><p>Using the AsyncTask class, so for the library methods
  getUserList(...) I'll have to create a dedicated AsyncTask class.</p>
  
  <pre><code>public class FetchTask extends AsyncTask&lt;Void, Void, Boolean&gt; {
  
  private List&lt;User&gt; users;
  protected Boolean doInBackground(Void... params) 
  {
      users = getUserList(...);
  }
  
  protected void onPostExecute(final Boolean success) 
  {
  //inform user list fragment that user data has been fetched successfully
  }
  </code></pre>
  
  <p>}</p>
  
  <p>If I
  use this method it means I will have to create an asyncTask class
  for every network call made(which is a significant amount) and have
  it communicate with the UI thread on completion</p></li>
  <li><p>Directly spinning off a thread to wrap the synchronous call </p>
  
  <pre><code>public class UserListFragment extends ListFragment
   {
      private List&lt;User&gt; users;
      private ArrayAdapter&lt;User&gt; userAdapter
      ....
  
      protected void OnCreate(Bundle savedInstance)
      {
          super.OnCreate
  
          new Thread(new Runnable(){
  
              public void run(){
  
                  users = getUserList()
                  //notify array adapter that data has changed
              }
          })
  
      }
   }
  </code></pre></li>
  </ol>
  
  <p>This method also requires that I repeat this for every synchronous method call I make and can easily get unwieldy.</p>
  
  <ol start="3">
  <li>The last method is using the Threadpoolexecutor, I must admit I
  don't yet fully understand this method.</li>
  </ol>
  
  <p>Again, my question is what is the preferred method of achieving this goal? Is it any of the 3 that I've listed? Thanks.</p>