title: Android - How can I update data or UI in my Activity when Push Notification FCM is received?
body: <p>I have the following <code>FirebaseMessagingService</code> which works fine when I get a push notification and the app is in foreground:</p>
  
  <pre><code>public class _FCMService extends FirebaseMessagingService {
     @Override
     public void onMessageReceived(RemoteMessage remoteMessage) {
        if (remoteMessage.getData().size() &gt; 0) {
           // Log.i(TAG, "PUSH PAYLOAD: " + remoteMessage.getData());
  
           JSONObject pushData = new JSONObject(remoteMessage.getData());
           pushType = pushData.optString("pushType");
           pushMessage = pushData.optString("body");
           Log.i(TAG, "ON PUSH RECEIVED - pushType: " + pushType);
           Log.i(TAG, "ON PUSH RECEIVED - pushMessage: " + pushMessage);
  
  
           Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
           NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                   .setContentText(pushMessage)
                   .setStyle(new NotificationCompat.BigTextStyle())
                   .setAutoCancel(true)
                   .setSmallIcon(R.mipmap.ic_launcher)
                   .setSound(defaultSoundUri);
           NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
           assert notificationManager != null;
           notificationManager.notify(0 , notificationBuilder.build());
        }
     }
  
  
  
     @Override
     public void onNewToken(@NotNull String token) {
        Log.i(TAG, "Refreshed token: " + token);
        ANDROID_DEVICE_TOKEN = token;
     }
  }
  </code></pre>
  
  <p>So, If I receive a push, the Logcat prints out the notification's body and (if present) the <code>pushType</code> string.</p>
  
  <p>What I would need to do is to make my other Activity update data when push is received, as well as get the <code>pushMessage</code> and <code>pushType</code> strings.</p>
  
  <p>I know how to do that in iOS Swift - by using <code>NotificationCenter</code> - but have no idea about Android, I've tried <code>LocalBroadcaster</code>, but no success.</p>