0

Question 1: Is it possible to download image file without giving the reference to ImageView?

Question 2: Can i download each file in a separage instance of aQuery or do i have to download the file sequentially? e.g, waiting for the callback of current file download and then trigger the next file download call? Below is my code

// Ad is my custom model class

// adList is my list of Ads having URL's to the ads hosted somewhere

// imageView is an invisible imageView as downloading does not start if i don't give any reference to any imageView resource

for (String adUrl : adList) {

    if (adUrl.length() > 0) {
        AQuery aQuery = new AQuery(DownloadAdActivity.this);
        BitmapAjaxCallback callback = new BitmapAjaxCallback(); 
        callBack.url(adUrl);
        callBack.fallback(R.id.placeHolderResource);
        callBack.fileCache(true);
        callBack.memCache(true);
        aQuery.id(imageView).image(callBack);

    }

}

I need to download 20/30 images when the app starts first time, so far i am doing it by giving a hidden imageView reference and trigging the aQuery sequentially after each image has downloaded. I tried to generate 20/30 request in a loop but only the last aQuery trigger call works which cancels the previous image download call.

Please guide me: 1- How to cache images without giving any reference to the imageView 2- How to download images in parallel manner, not in sequential manner through AQuery.

Abdul Samad
  • 526
  • 5
  • 13

4 Answers4

2

1) You can use ajax call without ImageView reference to download image.

androidQuery.ajax("url", Bitmap.class, 0, new AjaxCallback<Bitmap>() {
            @Override
            public void callback(String url, Bitmap bitmap, AjaxStatus status) {
                super.callback(url, bitmap, status);

            }
        });

2) By default you can download 4 images concurrently. But you can change as per your requirement like this

AjaxCallback.setNetworkLimit(8);
Biraj Zalavadia
  • 28,348
  • 10
  • 61
  • 77
0

You can use Picasso It will make all the downloads and also the caching for the images.

Anyway if the images are quite small you should prepare a "zip" file and dl all of them with an AsyncTask / Thread and unzip them. Opening and closing the connections to the server are "very expensive" operations in time consuming.

Community
  • 1
  • 1
danysz
  • 580
  • 3
  • 11
  • Thank you for the post, androidQuery is more strong, lighter and faster than other libraries i have used. – Abdul Samad Oct 22 '14 at 19:03
  • I used in the past AQuery but in last 8 months is not actually update anymore so I prefer to use something that is continually maintained. but this is something really personal. – danysz Oct 22 '14 at 19:34
0

Here is method to obtain bitmap from url using AQuery static Bitmap myBitmap = null;

public static Bitmap getBitmapFromURL(String src) {
    try {
        Log.i(TAG, "Image Url is : " + src);
        AQuery androidQuery = new AQuery(ChatApplication.getInstance());
        androidQuery.ajax(src, Bitmap.class, 0, new AjaxCallback<Bitmap>() {
            @Override
            public void callback(String url, Bitmap bitmap, AjaxStatus status) {
                super.callback(url, bitmap, status);
                if (bitmap != null)
                    myBitmap = bitmap;
            }
        });
    } catch (Exception e) {
        Log.i(TAG, "Error due to " + e);
    }
    return myBitmap;
}
0
    AQuery aq = new AQuery(context);
    aq.ajax(url_of_image, Bitmap.class, new AjaxCallback<Bitmap>() {

        @Override
        public void callback(String url, Bitmap object, AjaxStatus status) {

        }
    });

Im sorry for replying late,But this is best library I have ever came across.

Yes,You can download. Bitmap object will give you the image.

You can create multiple instances of Aquery if you want to download or pass the each URL after one download finishes,you can use any loop for that.

Anshul Verma
  • 347
  • 1
  • 5
  • 18