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());
}