title: How to send data from a class to an Activity in Android
body: <p>I am implementing FCM(Firebase cloud messaging) for push notifications. I could get push notification from the server using my service class successfully. But, how do I send data(messages) from the service class to the activity?</p>
  
  <p><strong>Service.java</strong></p>
  
  <pre><code>public class Service extends FirebaseMessagingService {
  
      private static final String TAG = "MyFirebaseMsgService";
  
      @Override
      public void onMessageReceived(RemoteMessage remoteMessage) {
  
          sendNotification(remoteMessage.getNotification().getBody());
      }
  
  
      private void sendNotification(String messageBody) {
  
          Intent intent = new Intent(this, FCMActivity.class);
          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                  PendingIntent.FLAG_ONE_SHOT);
  
          Uri defaultSoundUri =RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  
          NotificationCompat.Builder notificationBuilder = new
                  NotificationCompat.Builder(this)
                  .setSmallIcon(R.mipmap.ic_launcher)
                  .setContentTitle("Firebase Push Notification")
                  .setContentText(messageBody)
                  .setAutoCancel(true)
                  .setSound(defaultSoundUri)
                  .setContentIntent(pendingIntent);
          notificationBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
          notificationBuilder.setLights(Color.RED, 1000, 300);
          NotificationManager notificationManager =
                  (NotificationManager)
                          getSystemService(Context.NOTIFICATION_SERVICE);
  
          notificationManager.notify(0, notificationBuilder.build());
      }
  }
  </code></pre>
  
  <p><strong>FCMActivity.java</strong></p>
  
  <pre><code>public class FCMActivity extends AppCompatActivity {
      private TextView mTextView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_fcm);
  
          mTextView = (TextView) findViewById(R.id.txt);
      }
  }
  </code></pre>