This question is continuation to my previous question over stack overflow how-to-download-images-asynchronously-from-web-server . I am struggling to make the asynchronous list in blackberry. Now it is working fine for me. But it is giving me another problem now.
What I have done so far
- Created a list view taking value from the XML feed
- List is loaded with default thumbnail
- Created
RunnableFactory, limiting the thread pool size to 5 and then adding the runnable’s to it. Runnable objects has the capability to download the image from server. - Now list loads perfectly fine asynchronously.
Problem scenario
On loading of the list screen it is initializing the RunnableFactory and then starting download and render images in list. But, let say I have 50 number of rows in the list. And now 10 images downloaded successfully, and RunnableFactory is still in action. At this point press back key and then click next. Practically it should come to the list screen and then again initiate the download process freshly. But it is throwing IllegalThredState exception
My assumptions on this problem
As all the threads are running, I might have to cancel all of the threads on back key pressed. If this is the problem can you please let me know how could i do it? As i have created multiple threads how could i manage to stop all threads and then navigate back ?
This looks like a more complex system. can anyone help me to understand what else could be the possible fix for this problem?
if you are using any treadpool then you shutdown otherwise you can inturupt all treads on navigate to back.