2016-12-05 5 views
-1

Ich hoffe, jemand könnte mir hier helfen. Ich kann nicht herausfinden, was das verursacht. Ich teste Firebase Messaging. onMessageReceived erfolgreich getroffen, aber ich bekomme diese Fehlermeldung, wenn ich NotificationManager.notify nennen:Aktivität kann nicht zerstört werden ... java.lang.NullPointerException: Beobachter

E/UncaughtException: java.lang.RuntimeException: Kann nicht Aktivität zerstören {com.myproject.android/com.myproject.android .MainActivity}: java.lang.NullPointerException: Beobachter

public class MyFirebaseMessagingService extends FirebaseMessagingService { 
     public void onMessageReceived(RemoteMessage remoteMessage) { 
       RemoteMessage.Notification notification = remoteMessage.getNotification(); 
       createNotification(notification); 
     } 
    } 



private void createNotification(RemoteMessage.Notification notification) { 
    Context context = getBaseContext(); 
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setContentText(notification.getBody()); 
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
    mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build()); 
} 

Antwort

0

ich glaube, ich es herausgefunden. Ich hatte etwas Code in meiner MainActivity onDestroy, der nicht dort gewesen sein sollte. Der Fehler hat mich abgestoßen, weil ich keine Ahnung habe, warum meine MainActivity onDestroy hier aufgerufen wird.

Verwandte Themen