title: In Android, how can I run an AsyncTask one at a time?
body: <p>I have an AsyncTask that is called by a group of methods something like this:</p>
  
  <pre><code>makeCall1();
  makeCall2();
  makeCall3();
  makeCall4();
  makeCall5();
  </code></pre>
  
  <p>problem being each has a "status message" that needs to display while they run. Since I have them running like I do above they all run together and the "status message" does one massive change. What I'd like is to have it step through each call and only make the next one once the first AsyncTask is complete.</p>
  
  <p>My Async is done like below:</p>
  
  <pre><code>public class JSONParser extends AsyncTask&lt;String, String, JSONObject&gt; {
  
          InputStream is = null;
          JSONObject json = null;
          String outPut = "";
          protected void onPreExecute(String f){
  
          }
  
          @Override
          protected JSONObject doInBackground(String... params) {
              // TODO Auto-generated method stub
              ...
              publishProgress(params[3]);
              ...
  
              return json;
          }
  
          protected void onProgressUpdate(String...values) {
              statusMessage.setText(values[0]);
           }
  
          protected void onPostExecute(JSONObject result) {
  
          }
      }
  </code></pre>
  
  <p>What is the best way to make each call one at a time?</p>
  
  <p>----- EDIT -----</p>
  
  <p>Additional code as requested</p>
  
  <p>I've changed the names of things below and placed "...." where pieces of code aren't really relevant such when it saves to the database:</p>
  
  <pre><code>public class SplashScreen extends Activity {
  
       protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_splash_screen);
  
          statusMessage = (TextView) findViewById(R.id.statusMessage);
      }
  
      protected void onResume(){
          super.onStart();
          if(isNetworkAvailable()){
              statusMessage.setText("Connection Found");
              new Handler().postDelayed(new Runnable() {
                  @Override
                  public void run() {
                      // TODO Auto-generated method stub
                      final String appUpdateDate = null;
                      getAPI1(appUpdateDate);
                      getAPI2(appUpdateDate);
                      getAPI3(appUpdateDate);
                      getAPI4(appUpdateDate);
                      getAPI5(appUpdateDate);
                      getAPI6(appUpdateDate);
  
                      endSplash();
                  }
  
              }, SPLASH_TIME_OUT);
          }
          else {
              statusMessage.setText("No Connection Found");
              new Handler().postDelayed(new Runnable() {
                  @Override
                  public void run() {
                      // TODO Auto-generated method stub
                      endSplash();
                  }
  
              }, SPLASH_TIME_OUT);
          }
  
      }
  
      public void endSplash(){
  
          ....
          goes to main activity after timeout
          ....
  
      }
  
       private boolean isNetworkAvailable() {
          ....
          checks for internet connection
          ....
      }
  
      //this is an example of getAPI1. There are 5 more but each do a different database and api call. The AsyncTask is what does the api call and parses the json it returns.
      public void getAPI1(String appUpdateDate){
          String URL = "http://API_URL";
          String requestType = "X";
          String getType = "Y";
          URL = URL+requestType+"/"+getType;
          SQLiteDatabase database = APIDB.getWritableDatabase();
          try {
              JSONObject output = new JSONParser().execute(new String[] {URL,consumerKey,sharedSecret,"Updating X"}).get();
              JSONArray jsonx = output.getJSONArray("Data");
  
              ....
                          runs through jsonX and saves data to database
                          ....
  
  
          } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (ExecutionException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (JSONException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
      }
  
      public class JSONParser extends AsyncTask&lt;String, String, JSONObject&gt; {
  
          InputStream is = null;
          JSONObject json = null;
          String outPut = "";
          protected void onPreExecute(String f){
  
          }
  
          @Override
          protected JSONObject doInBackground(String... params) {
              // TODO Auto-generated method stub
              publishProgress(params[3]);
              String url = params[0];
              String ck = params[1];
              String ss = params[2];
              Log.d("url",url);
              Log.d("ck",ck);
              Log.d("ck",ss);
              List&lt;NameValuePair&gt; values = new ArrayList&lt;NameValuePair&gt;();
              values.add(new BasicNameValuePair("ConsumerKey", ck));
              values.add(new BasicNameValuePair("SharedSecret", ss));
              try {
  
                  ....
                          get the json from the api
                          ....
  
              } catch (UnsupportedEncodingException e) {
                  e.printStackTrace();
              } catch (ClientProtocolException e) {
                  e.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              }
  
              ....
                  parse the json to be returned
                  ....
  
              } catch (Exception e) {
                  Log.e("Buffer Error", "Error converting result " + e.toString());
              }
              try {
                  json = new JSONObject(outPut);
              } catch (JSONException e) {
                  Log.e("JSON Parser", "Error parsing data " + e.toString());
              }
              // return JSON String
  
              return json;
          }
  
          protected void onProgressUpdate(String...values) {
              statusMessage.setText(values[0]);
           }
  
          protected void onPostExecute(JSONObject result) {
          }
      }
  
  }
  </code></pre>