title: How to show push notification using firebase when app is destroyed
body: <p>I have an app that consumes firebase messaging service to recieve push notifications.</p>
  
  <p>I already searched for the differences between using "notification" or "data" while sending the notification information to the FCM sending server.</p>
  
  <p>My notification doesn't appear when the app is destroyed, only while it is on foreground or background. </p>
  
  <p>I need to make it so that my server ocassionally send a push notification to the device every once and a while (about twice a week or so) but the app should be able to display the notification while it is closed.</p>
  
  <p>Any idea how I can do this? This is my notification json encoded string that i am sending to the FCM sending server:</p>
  
  <pre><code>{
  "to":"d_kQKDkq5V4:APA91bG4hIyqbr2a_24nUIe6jVbySS90FMnVKwwuTfG1dV3OooeAc_555XkB2e_h_oWzEOMde8uIt2ESvv_Thl1J1sEXDHWPsLCE7EdMXkZ_AS6xlVq8uJIjVojz1WPxqiUjWZm65Ypf",
  "data":{
              "title":"App in background again",
              "body":"asdsad"
         }
  }
  </code></pre>
  
  <p>So the notification appears while the app is on background or foreground, but it doesn't appear while it is destroyed. How do i make it so it can still recieve and display the notification while the app is destroyed?</p>
  
  <p>This is my onMessageRecieved() method:</p>
  
  <pre><code>public void onMessageReceived(RemoteMessage remoteMessage) {
          /*String title = remoteMessage.getNotification().getTitle();
          String message = remoteMessage.getNotification().getBody();
            */
          Log.e("REG_TOKEN",remoteMessage.getData().get("title"));
          Map&lt;String,String&gt; data = remoteMessage.getData();
          String title = data.get("title");
          String message = data.get("body");
          Intent intent = new Intent(this, MainActivity.class);
          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
  
          NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
          notificationBuilder.setContentTitle(title)
                  .setContentText(message)
                  .setSmallIcon(R.mipmap.ic_launcher_round)
                  .setAutoCancel(true)
                  .setContentIntent(pendingIntent);
  
          NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
          notificationManager.notify(0, notificationBuilder.build());
  
  
      }
  </code></pre>