In my application, I load some URL from my database and store them in an ArrayList<Bitmap>
to put them in a gallery. It works good, but it's very slow. The problem is that I load all the bitmap in the ArrayList
before showing the images.
try
{
JSONArray jArray = new JSONArray(result);
for(int i=0;i<jArray.length();i++)
{
Temp = jArray.get(i).toString();
HttpURLConnection connection = null;
try
{
connection = (HttpURLConnection) new URL(Temp).openConnection();
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
connection.connect();
InputStream input = connection.getInputStream();
x = BitmapFactory.decodeStream(input);
bitmapArray.add(x);
}
}
return bitmapArray; // returning the array list with all the bitmaps inside
protected void onPostExecute(ArrayList<Bitmap> donnees)
{
SetupInterface(); // This method sends the arraylist to an image adatper and display bitmaps to the screen.
}
My problem is that SetupInterface()
is called only when the array is full and returned. So when I open my activity, it takes about 4-5 seconds to display the gallery, because is has to load all the bitmaps inside the array before displying them. How to do it faster?