open fragment from Firebase onMessageReceived
<p>I'm trying to open a fragment when a new Notification is received. For this I use a BroadcastReceiver. Problem is I'm not getting the message in my Activity from <code>sendNotification</code> method inside <code>FirebaseMessagingService</code> class. I think the issue is I declared the IntentFilter inside <code>onCreate</code> and its not being called when I click on the push notification. Is there any other way to do this?</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>// Globally declared
 private IntentFilter mIntentFilter;
 
 @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
  
  // Open a fragment automatically
   if (findViewById(R.id.frame) != null) {
            if (savedInstanceState != null) {
                return;
            }

            myFragmentManager = getSupportFragmentManager();
            myFragmentTransaction = myFragmentManager.beginTransaction();
            myFragmentTransaction.replace(R.id.frame, new ProdList()).commit();
        }
        

        mIntentFilter = new IntentFilter();
        mIntentFilter.addAction("com.sam.CUSTOM_INTENT");


    } 
 
 @Override
    protected void onResume() {
        super.onResume();
        registerReceiver(mReceiver, mIntentFilter);
    }

    @Override
    protected void onPause() {
        super.onPause();
        unregisterReceiver(mReceiver);
    }
 
 private BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {

            if (intent.getAction().equals("com.sam.CUSTOM_INTENT")) {

                Toast.makeText(getApplicationContext(), "GOT MESSAGE", Toast.LENGTH_SHORT).show();
                InventoryList il = new InventoryList();
                replaceFragment(il,"IL");
            }
        }
    };</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code>@Override
    public void onMessageReceived(RemoteMessage remoteMessage) {        

        if (remoteMessage.getData().size() &gt; 0) {
            for (Map.Entry&lt;String, String&gt; entry : remoteMessage.getData().entrySet()) {
                
                String value = entry.getValue();
               
                try {
                    JSONObject obj = new JSONObject(value);
                    
                    sendNotification(obj.getString("message"),"SUCCESS");
                    

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }


    }
 
 
 private void sendNotification(String messageBody, String param) {
        Intent intent = new Intent(this, HomeActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
  intent.setAction("MESSAGE");

        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_com.sam.CUSTOM_INTENTr)
                .setContentTitle("Nika")
                .setContentText(messageBody)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(0, notificationBuilder.build());
    }</code></pre>
</div>
</div>
</p>