Pat
Pat

Reputation: 3

order of asynctask calling a function from a referenced class

I'm writing an Android app and was wondering something when using AsyncTasks. I have a class that coordinates network requests and should manage to only have one AsyncTasks at a time present. So if I have multiple AsyncTasks who have the same reference to the managerClass and they call to different functions at the same time -> are those functions executed one at a time or could it happen that parts of the first function are executed and then parts of the second function are executed without the first being finished?

Upvotes: 0

Views: 21

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93668

If you're using AsyncTasks- so long as you call execute and not executeOnExecutor, each AsyncTask will run one after another on the same thread. So as long as the UI thread isn't also accessing that manager class, you're safe. But realistically you should probably learn how to do locking and create critical regions where necessary.

Upvotes: 1

Related Questions