I have the following task:
- Download image from web
- Create another image using it
- Save image to SD card and show it
I need to do every step into another thread.
It seems, that when I’m done with loading image I need to transfer it into second thread.
After some googling I realized that I need to implement Callable interface to each thread and than use it with ExecutorService. The problem is that I don’t understant how to pass data, for example, from first thread to second.
Can anyone show a simple example of it? thanks
Use BlockingQueue and a Producer-Consumer pattern.
In this approach, the first thread will download your images and put them inside the queue.
The second thread will wait until something appears inside the queue, transform the image, and put it in another queue, that the third thread will wait for.
Read the articles I’ve linked to for more explanation and a working example of the Producer-Consumer pattern.