0

I have an async task that does a HTTP GET request and grab a JSON response. I call it like this in the onCreate method to grab the information from the server in the doInBackGround method.

 myTask.execute(new String[] {firsturl});

I want to wait until this is over and grab another JSON response from a different URL in the onCreate method. I don't necessarily need to wait until the above asynch task process is done, but I would like to reuse to code. So I did;

 myTask.execute(new String[] {secondurl});

This gives me the error that the first task is still running. How do I call the same asynch task twice in the onCreate method?

thanks!

user3853858
  • 235
  • 1
  • 4
  • 10

2 Answers2

0

You need to create another object (instance) to run the AsyncTask again. Also, you should use libraries like loopj or okhhtp to handle network requests.

mbmc
  • 5,024
  • 5
  • 25
  • 53
0

The instances on AsyncTask can be called only one time. You need create two instances of AsyncTask, and call the first with first url and the second with the another url.

Jose Rodriguez
  • 9,753
  • 13
  • 36
  • 52