Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trying to use a recycled bitmap android.graphics.Bitmap #1550

Closed
sungerk opened this issue Nov 22, 2016 · 1 comment
Closed

trying to use a recycled bitmap android.graphics.Bitmap #1550

sungerk opened this issue Nov 22, 2016 · 1 comment
Labels

Comments

@sungerk
Copy link

@sungerk sungerk commented Nov 22, 2016

    public  static  void dispaly(String url, ImageView imageView){
        ImagePipeline imagePipeline = Fresco.getImagePipeline();
        ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(getUri(url));
        ImageRequest request = builder.build();
        DataSource<CloseableReference<CloseableImage>>
                dataSource = imagePipeline.fetchDecodedImage(request, DuApplicaiton.getInstance());
        dataSource.subscribe(new BaseBitmapDataSubscriber() {
            @Override
            protected void onNewResultImpl(Bitmap bitmap) {
                imageView.setImageBitmap(bitmap);
            }

            @Override
            protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {

            }
        }, CallerThreadExecutor.getInstance());
    }

the code run in android 6.0.1 Exception
my phone os is cm13

but the code can run normally in other android OS

@kirwan

This comment has been minimized.

Copy link
Contributor

@kirwan kirwan commented Nov 22, 2016

You shouldn't use a BaseBitmapDataSubscriber and then set the bitmap to an ImageView as the bitmap could be recycled any time after onNewResultImpl() completes.

We strongly recommend using a DraweeView instead of ImageView as it handles the lifecycle of the bitmap. If you must use an ImageView, you will have to use a BaseDataSubscriber<CloseableReference<CloseableImage>> and keep the CloseableReference until the image is no longer needed and then finally close it (for example, in onDestroy().

Take a look under "To get decoded image…" in this page of the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.