I am writing an application in which I need to show images from the URLs. Now suppose I have to show 100 images, one after the another and each photo needs to be downloaded from the internet.
I am using the Gallery View to show the images, but the problem is when I pass the URL to getView function it starts downloading all the 100 images (yes in Async Task only), but downloading 100 images slows down the system. What I want to achieve is, when i move right, my program should pick the url and download it from the internet.
public class ViewImage extends Activity {
private String albumID;
private ArrayList<MediaBO>galleryList;
private Context context;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.localgallery);
    this.context = this;
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    albumID = extras.getString("albumID");
    int position = extras.getInt("position"); //position of the image selected
    DataBaseOperation dataBaseOperation = new DataBaseOperation(this);
    galleryList = dataBaseOperation.queryAllPhoto(albumID); //this returns the list of Photos needs to be shown.it has the URL of the photos
    Gallery g = (Gallery) findViewById(R.id.localGallery);
    g.setAdapter(new ImageAdapter(this));
    g.setSelection(position);
}
public class ImageAdapter extends BaseAdapter{
    private Context mContext;
    int mGalleryItemBackground;
    public ImageAdapter(Context c) {
        mContext = c;
    }
    public int getCount(){
        return galleryList.size();
    }
    public Object getItem(int position){
        return position;
    }
    public long getItemId(int position) {
        return position;
    }
    public View getView(int position, View convertView, ViewGroup parent){
        ImageView i = new ImageView(mContext);
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.localgallery, null);
        }
        String url = galleryList.get(position).getUrl();
        DOWNLOAD()//download the photo using Async Task
        v = i;
        return v;
    }
}
   }
Now the problem here is getview is called as soon as the activity is loaded for all the URL present in the GalleyList which slows down the system
@cyngus: i was trying to use your answer.. but now sure how to use this..
I created the executor object as suggested by you
    Executor e = new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE,
            TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
But i m not able to find out how to use this for calling my Async Task(BitmapDownloaderTask)
    BitmapDownloaderTask task = new BitmapDownloaderTask(con,showDialog,i,path);
    task.execute(url,null,null);
My Asyn Task is
    private class BitmapDownloaderTask extends AsyncTask<String, Void, Bitmap> {
    }
 
     
     
     
    