Android - Async Task behavior in 2.3.3 and 4.0 OS

前端 未结 3 1114
忘了有多久
忘了有多久 2020-12-10 18:26

I am testing an application where we have a list view with list of images retrieved over network. When i run the application on android device 2.3.3 (WIFI speed 512 KBPS) an

3条回答
  •  旧巷少年郎
    2020-12-10 19:02

    You can use the AsyncTaskCompat.executeInParallel for API < 11, you find this class in the appcompat v4 library.

    An exemple of use :

    AsyncTaskCompat.executeParallel(new AsyncTask() {
            @Override
            protected Bitmap doInBackground(Void... params) {
                return MediaStore.Images.Thumbnails.getThumbnail(
                        imageView.getContext().getContentResolver(),
                        id,
                        MediaStore.Images.Thumbnails.MINI_KIND,
                        null);
            }
            @Override
            protected void onPostExecute(Bitmap bitmap) {
                imageView.setImageBitmap(bitmap);
                if (bitmap != null) {
                    // Add the image to the memory cache first
                    CACHE.put(id, bitmap);
                    if (listener != null) {
                        listener.onImageLoaded(bitmap);
                    }
                }
            }
        });
    

    enjoy

提交回复
热议问题