Glide: How to use this in notification service?

Created on 22 Aug 2017  路  3Comments  路  Source: bumptech/glide


Glide Version:
glide:4.0.0

Integration libraries:
okhttp:3.3.1
com.android.volley:volley:1.0.0
jp.wasabeef:glide-transformations:2.0.2


Device/Android Version:
Android 6.0, 5.0, 4.2


Issue details / Repro steps / Use case background:


Glide load line / GlideModule (if any) / list Adapter code (if any):

Glide.with...

```
Glide.with(getApplicationContext()).asBitmap().load(strURL).into(new SimpleTarget(){

            @Override
            public void onResourceReady(Bitmap bitmap, Transition<? super Bitmap> transition) {
                if (bitmap != null) {
                    NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
                    bigPictureStyle.bigPicture(bitmap);
                    notificationBuilder.setStyle(bigPictureStyle);

                    Notification notification = notificationBuilder.build();
                    NotificationManager notificationManager =
                            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                    notificationManager.notify(0, notification);
                }
            }
        });


Stack trace / LogCat:

paste stack trace and/or log here

You must call this method on the main thread

When I received a notification, the app crash because of Glide.with(getApplicationContext()).
Called at MyFirebaseMessagingService.onMessageReceived()

question

Most helpful comment

I found the answer is....

final NotificationTarget target = new NotificationTarget(context, R.id.imgBigImage, rv, notification, 0);
new Handler(Looper.getMainLooper()).post(new Runnable() {
                @Override
                public void run() {
                    Glide.get(getApplicationContext()).clearMemory();
                    Glide.with(getApplicationContext())
                            .asBitmap()
                            .load(strURL)
                            .into(target);
                }
            });

All 3 comments

I found the answer is....

final NotificationTarget target = new NotificationTarget(context, R.id.imgBigImage, rv, notification, 0);
new Handler(Looper.getMainLooper()).post(new Runnable() {
                @Override
                public void run() {
                    Glide.get(getApplicationContext()).clearMemory();
                    Glide.with(getApplicationContext())
                            .asBitmap()
                            .load(strURL)
                            .into(target);
                }
            });

Thank you!

@kenneth2008 can you please update us with the syntax for the latest version of Glide?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Anton111111 picture Anton111111  路  3Comments

Tryking picture Tryking  路  3Comments

mttmllns picture mttmllns  路  3Comments

Ncit picture Ncit  路  3Comments

MrFuFuFu picture MrFuFuFu  路  3Comments