title: FCM notification not opening intended activity Android
body: <p>I am trying to get notification generated by FCM console and I am receiving them but I am unable to override <code>onMessageReceived</code> of FirebaseMessagingService. Don't know what I am doing wrong.</p>
  
  <p><strong>MyFirebaseMessagingService</strong> class responsible for handling notifications:</p>
  
  <pre><code>public class MyFirebaseMessagingService extends FirebaseMessagingService {
      private static final String TAG = "MyFirebaseMsgService";
  
      @Override
      public void onCreate() {
          super.onCreate();
      }
  
      @Override
      public void onMessageReceived(RemoteMessage remoteMessage) {
  
          Log.d(TAG, "FROM:" + remoteMessage.getFrom());
  
          //Check if the message contains data
          if(remoteMessage.getData().size() &gt; 0) {
              Log.d(TAG, "Message data: " + remoteMessage.getData());
          }
  
          //Check if the message contains notification
  
          if(remoteMessage.getNotification() != null) {
              Log.d(TAG, "Mesage body:" + remoteMessage.getNotification().getBody());
              sendNotification(remoteMessage.getNotification().getBody(),remoteMessage.getData());
          }
      }
  
      /**
       * Dispay the notification
       * @param body
       */
      private void sendNotification(String body , Map&lt;String,String&gt; data) {
  
  //        int finalSecId = Integer.parseInt((String) data.get("sec_id"));
  //        int sec = Integer.parseInt((String) data.get("sec"));
          Intent intent = new Intent(this, InsuranceActivity.class);
          intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0/*Request code*/, intent, PendingIntent.FLAG_ONE_SHOT);
          //Set sound of notification
          Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  
          NotificationCompat.Builder notifiBuilder = new NotificationCompat.Builder(this)
                  .setSmallIcon(R.drawable.login_meter)
                  .setContentTitle(getString(R.string.app_name))
                  .setContentText((String) data.get("sec_id")+ " "+(String) data.get("sec"))
                  .setAutoCancel(true)
                  .setSound(notificationSound)
                  .setContentIntent(pendingIntent);
  
          NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
          notificationManager.notify(0 /*ID of notification*/, notifiBuilder.build());
      }
  }
  </code></pre>
  
  <p>And Inside Application tag</p>
  
  <pre><code>&lt;service android:name=".Fcm.MyFirebaseMessagingService"
              android:enabled="true"
              android:exported="true"
              &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.google.firebase.MESSAGING_EVENT"/&gt;
              &lt;/intent-filter&gt;
          &lt;/service&gt;
          &lt;service android:name=".Fcm.MyFirebaseInstanceIDService"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.google.firebase.INSTANCE_ID_EVENT"/&gt;
              &lt;/intent-filter&gt;
          &lt;/service&gt;
  </code></pre>