Run another AsyncTask in onPostExecute()

前端 未结 2 1099
醉梦人生
醉梦人生 2021-01-11 13:00

What if I need to run another async task being in another async task, meaning in onPostExecute() method, how to do so?

相关标签:
2条回答
  • 2021-01-11 13:39

    As a recommendation, try to off-load as many time's taking calls in your first AsyncTask as you can. However, if your application design is in such a way that you only need to execute another task once the first task is completed then simply execute the second AsyncTask exactly in the same way as you are doing for the first one.

    @Override
    protected void onPostExecute(String result) {
         new MySecondAsyncTask().execute(params);   //params if any
    }
    
    0 讨论(0)
  • 2021-01-11 13:59

    You can try the following code to create a NewAsyncTask in onPostExecute and then execute the new task.

    @Override
    protected void onPostExecute(String result) {
        NewAsyncTask newtask = new NewAsyncTask();
        newtask.execute();    
    }
    
    0 讨论(0)
提交回复
热议问题