In my Android program, I have to do 4 or 5 network calls. Each are independent, and each can run on their own.
public void backGroundTasks() {
new AsyncTasks<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
List<User> users = RetrofitAdapter.getClient().getUsersSync();
saveToDB(users);
} catch (RetrofitError error) {
error.printStackTrace();
}
return null;
}
}.execute();
new AsyncTasks<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
List<Media> contents = RetrofitAdapter.getClient().getContentsSync();
saveToDB(contents);
} catch (RetrofitError error) {
error.printStackTrace();
}
return null;
}
}.execute();
new AsyncTasks<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
Profile profile = RetrofitAdapter.getClient().getProfile();
saveToDB(profile);
} catch (RetrofitError error) {
error.printStackTrace();
}
return null;
}
}.execute();
new AsyncTasks<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
List<Message> messages = RetrofitAdapter.getClient().getMessages();
saveToDB(messages);
} catch (RetrofitError error) {
error.printStackTrace();
}
return null;
}
}.execute();
}
My questions are,
How this AsyncTask
work ?
Will be executed in parallel ? or Will be invoked but the network requests will be queued ?
In some SO answers they have mentioned to do execute AsyncTasks
with executeOnExecutor()
. Will it help for this scenario ?
Note: I use Retrofit library for making REST calls easier. Does it have anything with this problem ?