Answer the question
In order to leave comments, you need to log in
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
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.
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 questionAsk a Question
731 491 924 answers to any question