J
J
Julia2015-08-24 17:09:18
Java
Julia, 2015-08-24 17:09:18

Is it possible to create two AsyncTasks in the same class?

The logic for working with connections is moved to a separate class. There is already one task that performs a network connection and receives data of a certain type and format. You also need a task that will download images from the network. Is it possible to add a second task in the same class and is it worth it at all (how optimal and logical is this)? Or is it preferable to somehow optimize the existing task to complete all tasks?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
LeEnot, 2015-08-24
@YushkaD

Of course, you can add as many AsyncTasks as you like in the class, but for loading images, I would recommend using a specialized library like Picasso , Glide , UniversalImageLoader or similar.
What benefits do you get?
1. Asynchronous loading of images without headaches
2. Optional image caching - including in RAM and on sdcard
3. Scaling and converting images into thumbnails
4. Many more pleasant little things - see settings and library options
By the way, Googlers for their projects I use Glide, a lot of developers use Picasso - so there will be no shortage of support.

G
Gregary, 2015-09-03
@Gregary

I have faced this issue many times. For myself, I decided to use HaMeR (Handler, Message, Runnable). In short, in my projects I do this: I create a Manager (which is the successor of Handler). With each request (for example, a request to download a picture), I create a Thread in which, at the end of the work, I do something like this
And then in Manager'e in the method handleMessage (Message msg) on ​​the switch I decide what to do next. Or update the UI or make another request (in this case, the request may already be different)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question