I'm trying to download image in a Bitmap array with AsyncTask from an https URL
Here my code of AsyncTask:
class GetImages extends AsyncTask<String,Void,Bitmap>{
int position;
public GetImages(int i){
position=i;
}
@Override
protected void onPreExecute() { }
@Override
protected Bitmap doInBackground(String... strings) {
Log.i(TAG,"Enter in background!!!!!!!!!!!!!!!!!!");
String src=strings[0];
Bitmap bitmap=null;
InputStream in;
int responseCode=-1;
try {
URL url = new URL(src);
HttpsURLConnection httpURLConnection = (HttpsURLConnection) url.openConnection();
httpURLConnection.setDoOutput(true);
httpURLConnection.connect();
responseCode = httpURLConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
in = httpURLConnection.getInputStream();
bitmap = BitmapFactory.decodeStream(in);
in.close();
}
Log.i(TAG,"OK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
} catch (MalformedURLException e) {
Log.i(TAG,"!!!!!!!!!Errore1");
e.printStackTrace();
} catch (IOException e) {
Log.i(TAG,"!!!!!!!!!Errore2");
e.printStackTrace();
}
return bitmap;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
Log.i(TAG,"Saving!!!!!!!!!!!!!!!!!!!!!!!");
image[position]=bitmap;
}
}
Where image[] is a Bitmap array
And I execute my AsyncTask:
for(i=0;i<Array.length;i++){
...
new GetImages(i).execute(MyHttpsURL[i]);
}
What I want to do is to save images from my https urls and save it in a Bitmap array to reuse it in RecyclerView. The problem is that seems my code doesn't download and put images in array because when I use image[] in recycler view my ImageViews that should display downloaded images are empty. What's my error(s)? How can I save images from https in a Bitmap array?