user2630748
user2630748

Reputation: 1

Android ImageManager Google Game Services

We are trying to download avatars from Google Play Game Services at URIs like content :/ / ... through android-class ImageManager, but for unknown reasons, the class stops loading on same avatars, simply ceases to come in response OnImageLoadedListener. Each picture is a separate instance of the manager.

All avatars are valid (for the tests, each at least once loaded) no exceptions catch, the context in create manager is valid, tried everything, from the current Activity to getApplicationContext().

Tried to make loading and asynchronously and synchronously.

What is remarkable: after the last loader's action is always line in log with garbage collector and then do not continue to load (the application continues its work), although all references to objects are stored.

More often than not finish loading the last avatar.

Has anyone encountered a similar problem? Appears on versions from 2.3 to 4.2

Code in the alternate boot:

static ImageManager imageManager = null;
static int id = 0;
static Uri uri = null;

...

// ...
// change id & uri
// ...

imageManager = ImageManager.create(context);

Log.v("app", "LoadImageFromGoogle Manager created for Image #" + id);

imageManager.loadImage(new OnImageLoadedListener() {
    @Override
    public void onImageLoaded(Uri arg0, Drawable arg1) {
        try {
            Log.v("app", "LoadImageFromGoogle Image loaded #" + id);

            Bitmap bm = ((BitmapDrawable)arg1).getBitmap();
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byte[] byteArray = stream.toByteArray();

            // ... some code

            Log.v("app", "LoadImageFromGoogle Image added #" + id);
        } catch (Exception e) {
            Log.v("app", "LoadImageFromGoogle after loading Exception = " + e.toString());
        }
    }
}, uri, android.R.drawable.btn_star);

the last line in the log is always the case:

Log.v("app", "LoadImageFromGoogle Manager created for Image #" + id);

and the following message GC.

Upvotes: 0

Views: 1238

Answers (2)

Alex Cabrera
Alex Cabrera

Reputation: 373

I had the same problem. It looks like garbage collector can "clean" the listener before it can retrieve the image. The way to solve the problem is to implement the ImageManager.OnImageLoadedListener directly on your activity and not creating a new object on the moment.

Here you can find a related issue on google code: https://code.google.com/p/play-games-platform/issues/detail?id=14&can=1&sort=-status&colspec=ID%20Type%20Status%20Priority%20Platform%20Summary%20Stars

Never is to late ;)

Upvotes: 0

Bruno Oliveira
Bruno Oliveira

Reputation: 5076

Hmm.... I've never seen this issue. Are you sure you are feeding it a valid URI? My first guess would be that it might be an off-by-one error somewhere in your code where you're passing an invalid URI the last time you call imageManager.loadImage(). I'd try making the above code print the URIs it's trying to load as well as the image numbers, to see if something weird comes up.

If not, can you make a simple repro case and post it to our public bug tracker? http://code.google.com/p/play-games-platform

Thanks!

Upvotes: 1

Related Questions