title: Call Asynctask one after another in my android application
body: <p>I have an application that uses Asyncttask but i want to execute two tasks that too after one completes. But i am unable to do that so can you please just give me pseudo code.
  here is my Asynctask class</p>
  
  <pre><code>@SuppressWarnings("unused")
  private class getresponse extends AsyncTask&lt;String, Void, Void&gt;{
      ProgressDialog pd ;
  
      private Context _context;
  
      public getresponse(Context c)
      {
          _context = c;
      }
  
      @Override
      protected void onPreExecute() {
  
           progressDialog = new ProgressDialog(MainActivity.this);
           pd = new ProgressDialog(_context);
              pd.setTitle("Getting JSON details");
              pd.setMessage("Please wait...");
              pd.setCancelable(false);
              pd.setIndeterminate(true);
              pd.show();
          super.onPreExecute();
      }
  
  
      @SuppressWarnings("static-access")
      @Override
      protected Void doInBackground(String... params) {
          try {
              /*String t = finduserjson.substring(
                      finduserjson.indexOf("{"),
                      finduserjson.lastIndexOf(",{"));
              String j = "]}";
              finduserjson = t + j;
              Log.d("FINDUSERJSON", "FINDUSERJSON" + finduserjson);*/
              jsonobject1.put("username", params[0]);
              jsonobject1.put("udid",
                      "A892E0AB-6732-4F42-BEFA-3157315E9EE4");
              socket.emit("setPseudo", jsonobject1);
              socket.emit("findAllUsers", jsonobject1);
  
              Log.e("TAG",""+ socket.getId());
          } catch (JSONException | MalformedURLException e1) {
               if (pd.isShowing())
                      pd.dismiss();
              e1.printStackTrace();
          }
  
  
  
      return null;
      }
      @Override
      protected void onPostExecute(Void result) {
          // TODO Auto-generated method stub
          super.onPostExecute(result);
          try
          {
              if (pd.isShowing())
                  pd.dismiss();
          }
          catch(Exception e)
          {
  
          }
  
           /*String t = finduserjson.substring(
                      finduserjson.indexOf("{"), 
                      finduserjson.lastIndexOf(",{")); 
              String j = "]}";
              finduserjson = t + j;
              Log.d("FINDUSERJSON", "FINDUSERJSON" + finduserjson);
  
                Intent intent = new Intent(MainActivity.this,
                          MenuScreen.class);  
                  intent.putExtra("onlineuser", onlineuser);
                  intent.putExtra("finduser", finduserjson);
                  startActivity(intent);*/
          new getresponse111(MainActivity.this).execute();
      }
  
  
  
      @Override
      protected void onCancelled() {
          // TODO Auto-generated method stub
          super.onCancelled();
          pd.dismiss();
      }
  
  
  
  }
  private class getresponse111 extends AsyncTask&lt;Void, Void, Void&gt;{
  
  
      private Context _context;
  
      public getresponse111(Context c)
      {
          _context = c;
      }
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
      }
  
  
      @SuppressWarnings("static-access")
      @Override
      protected Void doInBackground(Void... params) {
          String t = finduserjson.substring(
                  finduserjson.indexOf("{"),
                  finduserjson.lastIndexOf(",{"));
          String j = "]}";
          finduserjson = t + j;
          Log.d("FINDUSERJSON", "FINDUSERJSON" + finduserjson);
  
  
  
      return null;
      }
      @Override
      protected void onPostExecute(Void result) {
          // TODO Auto-generated method stub
          super.onPostExecute(result);
  
                Intent intent = new Intent(MainActivity.this,
                          MenuScreen.class);  
                  intent.putExtra("onlineuser", onlineuser);
                  intent.putExtra("finduser", finduserjson);
                  startActivity(intent);
      }
  
  
  
      @Override
      protected void onCancelled() {
          // TODO Auto-generated method stub
          super.onCancelled();
  
      }
  
  
  
  }
  </code></pre>
  
  <p>Error is following</p>
  
  <pre><code>  09-25 13:00:30.997: E/AndroidRuntime(5906): FATAL EXCEPTION: AsyncTask #3
  09-25 13:00:30.997: E/AndroidRuntime(5906): java.lang.RuntimeException: An error occured while executing doInBackground()
  09-25 13:00:30.997: E/AndroidRuntime(5906):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
  09-25 13:00:30.997: E/AndroidRuntime(5906):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
  09-25 13:00:30.997: E/AndroidRuntime(5906):     at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
  09-25 13:00:30.997: E/AndroidRuntime(5906):     at java.util.concurrent.FutureTask.run(FutureTask.java:239)
  09-25 13:00:30.997: E/AndroidRuntime(5906):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
  09-25 13:00:30.997: E/AndroidRuntime(5906):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
  09-25 13:00:30.997: E/AndroidRuntime(5906):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
  09-25 13:00:30.997: E/AndroidRuntime(5906):     at java.lang.Thread.run(Thread.java:841)
  09-25 13:00:30.997: E/AndroidRuntime(5906): Caused by: java.lang.NullPointerException
  09-25 13:00:30.997: E/AndroidRuntime(5906):     at com.example.socketserver.MainActivity$getresponse111.doInBackground(MainActivity.java:231)
  09-25 13:00:30.997: E/AndroidRuntime(5906):     at com.example.socketserver.MainActivity$getresponse111.doInBackground(MainActivity.java:1)
  09-25 13:00:30.997: E/AndroidRuntime(5906):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
  09-25 13:00:30.997: E/AndroidRuntime(5906):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
  09-25 13:00:30.997: E/AndroidRuntime(5906):     ... 4 more
  </code></pre>