2017-01-25 6 views
1

ich mit Glide ein Bild auf eine Push-Benachrichtigung zu laden bin versucht, aber es sagt dies:Glide: load Bild-Benachrichtigungen drücken

FATAL EXCEPTION: Thread-9730 
Process: com.monkingme.monkingmeapp, PID: 24226 
java.lang.IllegalArgumentException: You must call this method on the main thread at com.bumptech.glide.util.Util.assertMainThread(Util.java:135)                     

Und der Code verwendet:

NotificationTarget notificationTarget = new NotificationTarget(
       context, 
       rv, 
       R.id.remoteview_notification_icon, 
       notification, 
       NOTIFICATION_ID); 

Glide.with(context.getApplicationContext()) 
    .load(item.getString("cover_img")) 
    .asBitmap() 
    .placeholder(placeholder) 
    .error(placeholder) 
    .into(notificationTarget); 

Ich benutze MessageHandler von Aerogear ->https://aerogear.org/docs/guides/aerogear-android/push/

Die Sache ist, dass in einer Push-Benachrichtigung die App nicht ausgeführt wird, also gibt es keinen Hauptthread. Irgendein Vorschlag?

Antwort

4

versuchen auf diese Weise:

new Handler(Looper.getMainLooper()).post(new Runnable() { 
     @Override 
      public void run() { 
       Glide.with(context.getApplicationContext()) 
        .load(item.getString("cover_img")) 
        .asBitmap() 
        .placeholder(placeholder) 
        .error(placeholder) 
        .into(notificationTarget); 
     } 
    });