优化android从web数据库加载url

优化android从web数据库加载url,android,bitmap,android-asynctask,gallery,Android,Bitmap,Android Asynctask,Gallery,在我的应用程序中,我从数据库中加载一些URL,并将它们存储在ArrayList中,以将它们放在图库中。它工作得很好,但速度很慢。问题是我在显示图像之前加载了ArrayList中的所有位图 try { JSONArray jArray = new JSONArray(result); for(int i=0;i<jArray.length();i++) {

在我的应用程序中,我从数据库中加载一些URL,并将它们存储在ArrayList中,以将它们放在图库中。它工作得很好,但速度很慢。问题是我在显示图像之前加载了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。因此,当我打开“活动”时,显示gallery大约需要4-5秒,因为在显示它们之前,is必须加载数组中的所有位图。如何更快?下载图像和解码图像需要时间。你知道jArray的内容至少知道那些图片的长度和名称。。。。您应该直接将带有默认背景图像的数组发送到图像适配器,并使用AsyncTask逐个加载这些实际图像。

在活动加载的开始部分,仅显示第一个图像。显示活动并完成所有初始化工作后,将加载其余图像。你可以:

在后台线程中逐个加载它们,例如使用或。第二种方法更容易实现。 在必须加载下一个图像时加载下一个图像,例如用户单击“下一步”。这被称为延迟加载。
你能给我一个一个加载位图并将其发送到ImageAdapter的示例吗?我在postexecute中创建了一个新的asynctask,并一次又一次地调用我的方法,直到数组已满。。。这显然不是最好的方法。。。