user1028678
user1028678

Reputation: 21

Asynctask API call issue

I'm currently using an AsyncTask to make an API call and populate a list with data. I have a Sub Menu whose items can call the AsyncTask to populate the data, problem is that if i click quickly i end up with merged results obviously cause the AsyncTask is running at the same time as each other.

What is the best way to handle a situation like this? Sorry if this is a amateur question.

Upvotes: 2

Views: 181

Answers (2)

Rajdeep Dua
Rajdeep Dua

Reputation: 11230

You could configure only a single Asynch task to run at a time. A boolean variable which is set to true as soon as the asynch task starts and set to false as soon as it finishes.

Next call could wait for this to be set to false. You could also rate limit what is the min time after which only making the API call makes sense.

Upvotes: 0

nicholas.hauschild
nicholas.hauschild

Reputation: 42849

I would use a ProgressDialog to show that content is being updated, and when the update is complete, dismiss() the dialog. While this is happening, you should make sure that you are not accepting touch input on your ListView. (this may happen by default when the ProgressDialog is in front, I am not remembering currently...)

Take a look at this link for an example.

Upvotes: 1

Related Questions