0

I've looked at other questions and I failed to clarify my doubt as to call a task from another task, I have the following code:

protected List<Plan> doInBackground(String... params) 
    try {
        JSONParsePlans parseJSON = new JSONParsePlans();
        return parseJSON.execute(params[0], params[1], params[2]).get();
    } catch (InterruptedException e) {
        e.printStackTrace();
        return null;
    } catch (ExecutionExeption e) {
        e.printStackTrace();
        return null;
    }
}

parseJSON is a task, when I run the program does nothing, not even called to task, it's like what Android omitted for security.

2 Answers2

1

According to this StackOverflow Post:

but only inside onProgressUpdate() or onPostExecute() since these methods runs on the UI thread. Therefore, start the second AsyncTask on the UI thread by choosing one of the two methods listed above.

So you can call an AsyncTask from another AsyncTask, so long as it runs in either of those two methods.

There is also another StackOverflow post that addresses this issue here

Community
  • 1
  • 1
freddiev4
  • 2,501
  • 2
  • 26
  • 46
1

It is possible to call an Async Task from another Async Task

but only inside onProgressUpdate() or onPostExecute()

Reason - since these methods runs on the UI thread. Therefore, start the second AsyncTask on the UI thread by choosing one of the two methods listed above.

Prem
  • 4,823
  • 4
  • 31
  • 63