title: Send data to activity when Firebase notification is clicked in Android
body: <p>In my application I want use <strong>fireBase</strong> for <strong>notification</strong>.<br>
  I want when click on notification (when app is closed, my mean is app is <code>background</code>) send data with <code>putExtra</code> to <strong>mainActivity</strong>.<br>
  I write below codes, but when click on <strong>notification</strong> (in app is background) but show me <strong>null</strong> for <code>getStringExtra</code> !<br></p>
  
  <p><strong>MyNotificationManager class :</strong> </p>
  
  <pre><code>public class MyNotificationManager {
  
      private Context mCtx;
      private Uri soundUri;
      private static MyNotificationManager mInstance;
  
      public MyNotificationManager(Context context) {
          mCtx = context;
      }
  
      public static synchronized MyNotificationManager getInstance(Context context) {
          if (mInstance == null) {
              mInstance = new MyNotificationManager(context);
          }
          return mInstance;
      }
  
      public void displayNotification(String title, String body) {
  
          soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  
          Intent intent = new Intent(mCtx, MainActivity.class);
          intent.putExtra("fcm_notification", "Y");
  
          PendingIntent pendingIntent = PendingIntent.getActivity(mCtx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  
          NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mCtx, Constants.NOTIF_CHANNEL_ID)
                  .setSmallIcon(R.mipmap.ic_launcher)
                  .setContentTitle(title)
                  .setSound(soundUri)
                  .setAutoCancel(true)
                  .setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400})
                  .setContentText(body)
                  .setContentIntent(pendingIntent);
  
          NotificationManager mNotifyMgr = (NotificationManager) mCtx.getSystemService(NOTIFICATION_SERVICE);
  
          if (mNotifyMgr != null) {
              mNotifyMgr.notify(1, mBuilder.build());
          }
      }
  }
  </code></pre>
  
  <p><strong>MyFirebaseMessagingService class :</strong> </p>
  
  <pre><code>public class MyFirebaseMessagingService extends FirebaseMessagingService {
  
      @Override
      public void onMessageReceived(RemoteMessage remoteMessage) {
          showNotify(remoteMessage.getFrom(), remoteMessage.getNotification().getBody());
      }
  
      private void showNotify(String title, String body) {
          MyNotificationManager myNotificationManager = new MyNotificationManager(getApplicationContext());
          //myNotificationManager.displayNotification(title, body);
          myNotificationManager.displayNotification(title, body);
      }
  }
  </code></pre>
  
  <p><strong>MainActivity class :</strong></p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  if (checkIntent()) return;
  }
  
  @Override
  protected void onNewIntent(Intent intent) {
      super.onNewIntent(intent);
      new Handler().postDelayed(new Runnable() {
          @Override
          public void run() {
              checkIntent();
          }
      }, 1000);
  }
  
  private boolean checkIntent() {
      String value = getIntent().getStringExtra("fcm_notification");
      Toast.makeText(context, "" + value, Toast.LENGTH_SHORT).show();
  
      if (value == null) return false;
  
      if (value.equals("Y")) {
          startActivity(new Intent(this, LandingActivity.class));
          // open one activity.
  
      } else if (value.equals("another thing")) {
          // open another activity.
      }
  
      finish();
      return true;
  }
  </code></pre>
  
  <p>When click on notification (on app is background) , show me <strong>null</strong> message in <code>Toast</code> for this line <code>String value = getIntent().getStringExtra("fcm_notification");</code></p>
  
  <p>How can i fix it? </p>