In my Android app, I have a GridView
which uses a BaseAdapter
to load data from DynamoDB and S3 in order to set every cell.
This is the code which I'm using to get the items pictures from S3:
ExecutorService exec = Executors.newSingleThreadExecutor();
Future<Bitmap> future = exec.submit(new Callable<Bitmap>() {
@Override
public Bitmap call() {
try {
url = new URL(/*S3 url*/);
bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (MalformedURLException e) {
Log.e("Malformed", e.getMessage());
} catch (IOException e) {
Log.e("IO", e.getMessage());
}
return bmp;
}
});
try {
holder.itemImage.setImageBitmap(future.get());
} catch (ExecutionException e) {
Log.e("Execution", e.getMessage());
} catch (InterruptedException er) {
Log.e("Interrupted", er.getMessage());
}
The code gets a Bitmap
from S3 URL
, and sets the ImageView
on the GridView
cell layout as the .jpg
file on S3 URL. The problem is that getting the images from S3 takes very long.
Is there any way to speed this process? Maybe writing this code at the beginning and load it there?