I have an Android application that uses AsyncTasks to make get and post calls to send and retrieve data from server. All works fine but sometimes the async task takes a lot of time to execute and thus other async tasks have to wait (if more than 5 async tasks is there) so what will be the best alternative or how to increase the thread pool if it is safe to do so.
Asked
Active
Viewed 44 times
-1
-
You can use a thread for this use case. See here for reference: http://stackoverflow.com/a/1921759/896600 – Ben May 07 '15 at 10:44
-
@Ben so when calling on an async task, i execute it in a new thread? – Rashad.Z May 07 '15 at 10:56
1 Answers
1
Asynctask are implemented behind the scene using threadpool, the default pool size for asynctasks is 1(so you can't run 2 asynctasks in parallel). In newer versions of android the default Asynctask pool size is 5. It's possible to change it but not recommended.
You can just create thread like in the sample I attached before:
Thread thread = new Thread() {
@Override
public void run() {
try {
//Do http request here
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
thread.start();

Ben
- 129
- 1
- 3