title: Open activity after FCM notification click in Android
body: <p>I know there are multiple posts like this, but I have tried many solutions and nothing works for me.</p>
  
  <p>I am using a Firebase Cloud Messaging to send notifications. The notification arrives, but it opens the main activity, not the one that I want.</p>
  
  <p>I try and try, but keep failing with starting appropriate activity. Tried different Intent or PendingIntent settings, tried click_action, nothing works for me.</p>
  
  <p>I think that it is not even entering my FirebaseMessagingService, but I did everything like in the Firebase instruction.</p>
  
  <p>manifest:</p>
  
  <pre><code>  &lt;service
              android:name="com.packagename.FirebaseMessagingService"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.google.firebase.MESSAGING_EVENT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/service&gt;
  
   &lt;activity android:name="com.packagename.NotificationActivity"&gt;
              &lt;action android:name="OPEN_ACTIVITY_1" /&gt;
              &lt;category android:name="android.intent.category.DEFAULT" /&gt;
          &lt;/activity&gt;
  </code></pre>
  
  <p>FirebaseMessagingService:</p>
  
  <pre><code>    public class FirebaseMessagingService extends FirebaseMessagingService {
  
      private static String TAG = "Firebase";
  
      @Override
      public void onMessageReceived(RemoteMessage remoteMessage) {
  
          Log.d(TAG, "From: " + remoteMessage.getFrom());
          if (remoteMessage.getData().size() &gt; 0) {
              Log.d(TAG, "Message data payload: " + remoteMessage.getData());
          }
  
  
          if(remoteMessage.getNotification()!=null){
              Log.d(TAG,"Message body : "+remoteMessage.getNotification().getBody());
              sendNotification(remoteMessage.getNotification().getBody(), remoteMessage.getNotification().getTitle());
          }
      }
  
      private void sendNotification(String body, String title) {
          Intent notificationIntent = new Intent(this, NotificationActivity.class);
          notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
          notificationIntent.putExtra("notification", body);
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
  
          NotificationCompat.Builder notification =
                  new NotificationCompat.Builder(this)
                          .setSmallIcon(R.drawable.notification)
                          .setContentTitle(getString(R.string.app_name))
                          .setStyle(new NotificationCompat.BigTextStyle()
                                  .bigText(body)
                          .setBigContentTitle(title))
                          .setContentText(body)
                          .setContentIntent(pendingIntent)
                          .setAutoCancel(true)
                          .setDefaults(NotificationCompat.DEFAULT_SOUND);
  
          NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
          notificationManager.notify(0,notification.build());
      }
  }
  </code></pre>
  
  <p>Logs after click:</p>
  
  <pre><code>D/StatusBar: Clicked on content of 0|com.mypackagename|0|GCM-Notification:89893881|10177 , PendingIntent{cc15013: android.os.BinderProxy@e3031fc} , Intent { act=com.google.firebase.MESSAGING_EVENT cmp=com.mypackagename/com.google.firebase.iid.FirebaseInstanceIdInternalReceiver (has extras) }
  </code></pre>