Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android gms ImageManager never loads image

I'm attempting to draw an icon for an achievement using Google Play Game Services API.
However, it is silently failing.

Approach/Issue:

  • The URI for the image is retrieved successfully, exists and is valid.
  • I use ImageManager.loadImage to get the image, with an OnImageLoadedListener for callback (com.google.android.gms.common.images.ImageManager).
  • However OnImageLoadedListener's method, onImageLoaded, is never called.
  • No error's, no evidence, just completely ignored, I even waited 10 minutes just in case.

Code:

// Get URI [is valid, exists, is of type png, I checked]
Uri uri = getAchievementIconUri(id);

// Use ImageManager to get the icon image
ImageManager.create(context).
    loadImage(new ImageManager.OnImageLoadedListener() {

        @Override
        public void onImageLoaded(Uri u, Drawable d, boolean r) {

            /* 
             * This code is never reached, no call to onImageLoaded is made!
             */

        }
}, uri);
like image 465
JamieGL Avatar asked Oct 21 '25 22:10

JamieGL


1 Answers

It's probably a very late answer, but it might help other people experiencing the same. From the latest google documentation, https://developers.google.com/android/reference/com/google/android/gms/common/images/ImageManager.html#public-methods

Note that you should hold a reference to the listener provided until the callback is complete. For this reason, the use of anonymous implementations is discouraged.

This might explain the behaviour you experienced, as in the first code snippet provided, no reference to the Listener was retained.

like image 111
Alessia Avatar answered Oct 24 '25 18:10

Alessia