Reputation: 7251
I have one canvas where I am showing one image on center. This image is downloaded by url. Actually there are more images to be downloaded, that means if user clicks RIGHT I have to show next image if LEFT, I have to show another one image from backside. I have array of strings which storing images of url. I want to download previous and next image in background. How to do that?
Upvotes: 1
Views: 568
Reputation: 170
Do something like..
Thread t = new Thread(new Runnable(){
public void run() {
// Your code to download image here as you were doing earlier,
// for previous and next image
}
});
t.start();
Upvotes: 0
Reputation: 1266
Following are some of the issues that you need to consider for this requirement to work across a range of devices
and the list continues.....
Keeping in mind the above set of issues that you will land-up with a constructive answer to your problem is to create a network IO manager and a caching manager.
interface NetworkIoItem {
Object sourceComponent;
public void onImageDownload(Image image) {
//Trigger the source
}
}
.
class NetworkIoManager extends Threads {
Vector pendingRequestQueue;
:
:
public void run() {
//Wait on the pending request queue
//Process all the elements in pending request queue
//and again wait on this queue
}
}
.
class CacheManager {
Vector cachedContent;
public boolean checkIfCached() {
//Check in the cachedContent whether
//this image exists if so return true;
}
public Image fetchImage() {
//Check if the image is cached
//if so return this cached image
//else push a NetworkIoItem object to
//NetworkIOManager pending queue
}
}
Now for each image (current, left or right) call the CacheManager.fetchImage()
, this method will take care of providing you image either cached or downloaded from server. In the same method if the image is not cached it will add NetworkIoItem
objbect to the NetworkIoManager
pendingQueue and download it. On completion of download it will trigger NetworkIoItem.onImageDownload(...)
method.
You can use J2ME Polish's Touch feature to download a image in the NetworkIoManager
By using this approach you will do asynchronous image fetches to the request URL.
Upvotes: 1