Lazar K Lazar K - 4 months ago 72
Android Question

download images faster and more efficently

In my app, i repeat an AysnceTask that downloads images from my AWS bucket but they take a little bit to download (1/2 seconds usually) and when I am downloading 10 images it adds up and makes the user experience worse.

My question is: is there a faster way to download images from AWS S3?

Android code:

private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {

protected Bitmap doInBackground(String... urls) {

String PhotoURL = "https://s3.amazonaws.com/bucket/Images/" + productForImages;
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(PhotoURL).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}

return mIcon11;
}

protected void onPostExecute(Bitmap result) {

productColumn = 5;
productImages[productRow][productColumn] = result;

}
}


Using different services (like AWS), a GitHub, or another library to speed up downloading is possible!

Answer

Try the Glide library recommended by google.

It have more features compared to Picasso library.

Add this dependency in your gradle

compile 'com.github.bumptech.glide:glide:3.5.2'

Load your image using following code

Glide.with(context)
.load("//inthecheesefactory.com/uploads/source/glidepicasso/cover.jpg")
.into(yourImageView);

Reference - https://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en

Comments