title: How to check is app in foreground from service?
body: <p>I need to show notification to user only if application is not in foreground. Here is my public class MyFirebaseMessagingService extends </p>
  
  <pre><code>FirebaseMessagingService {
      @Override
      public void onMessageReceived(RemoteMessage remoteMessage) {
          if(applicationInForeground()) {
              Map&lt;String, String&gt; data = remoteMessage.getData();
              sendNotification(data.get("title"), data.get("detail"));
          }
  
      }
  </code></pre>
  
  <p>need to implement <code>applicationInForeground()</code> method</p>