【发布时间】:2012-12-31 10:33:15
【问题描述】:
在我的应用程序中,我从我的数据库中加载了一些 URL,并将它们存储在 ArrayList<Bitmap> 中,以便将它们放入图库中。它工作得很好,但速度很慢。问题是我在显示图像之前加载了ArrayList 中的所有位图。
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.
}
我的问题是 SetupInterface() 仅在数组已满并返回时才被调用。所以当我打开我的活动时,显示画廊大约需要 4-5 秒,因为在显示它们之前必须加载数组中的所有位图。怎么做更快?
【问题讨论】:
标签: android bitmap android-asynctask gallery