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

BaseBitmapDataSubscriber not being called #1532

firetrap opened this issue Nov 6, 2016 · 1 comment

BaseBitmapDataSubscriber not being called #1532

firetrap opened this issue Nov 6, 2016 · 1 comment


Copy link

@firetrap firetrap commented Nov 6, 2016

Hi i'am trying to reuse the bitmap from fresco, because i need to set as background in another view. The problem it's the BaseBitmapDataSubscriber it's not being called.

Here's my code:

 private void getFrescoImage(String url) {
        // To get image using Fresco

        Uri uri = Uri.parse(url);

        ImagePipeline imagePipeline = Fresco.getImagePipeline();
        ImageRequest imageRequest = ImageRequest.fromUri(uri);
        DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
        CallerThreadExecutor threadExecutor = CallerThreadExecutor.getInstance();
        //The code is executed until here

        try {
            dataSource.subscribe(new BaseBitmapDataSubscriber() {
                public void onNewResultImpl(@Nullable Bitmap bitmap) {
                    if (bitmap == null) {
                        Log.d(TAG, "Bitmap data source returned success, but bitmap null.");

                    setRecyclerItemAnimation(cardView, getAdapterPosition());
                    // The bitmap provided to this method is only guaranteed to be around
                    // for the lifespan of this method. The image pipeline frees the
                    // bitmap's memory after this method has completed.
                    // This is fine when passing the bitmap to a system process as
                    // Android automatically creates a copy.
                    // If you need to keep the bitmap around, look into using a
                    // BaseDataSubscriber instead of a BaseBitmapDataSubscriber.

                public void onFailureImpl(DataSource dataSource) {
                    // No cleanup required here

            }, threadExecutor);
        } finally {
            if (dataSource != null) {


This comment has been minimized.

Copy link

@oprisnik oprisnik commented Nov 8, 2016

As stated in the documentation (and your comment), this will not work since the bitmap could be released / recycled immediately after the call.

You can just get the decoded image, like you do, and then get the bitmap from the CloseableReference<CloseableImage> image and hold on to the result until you don't need the bitmap any more. Once you're done, do not forget to call CloseableReference.closeSafely(image).

See also and

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

Successfully merging a pull request may close this issue.

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