title: Why my onMessageReceived in FirebaseMessagingService do not run
body: <p>I'm trying to create an App receive Notification form Firebase Cloud Messaging. But it is not working:</p>
  
  <p>Seemly the onMessageReceived don't run, i try to write an log to see the message when i send it from firebase to app, but i can't see anything. This is my code:</p>
  
  <p>My MyFirebaseMessagingService class:</p>
  
  <pre><code>public class MyFirebaseMessagingService extends FirebaseMessagingService {
      @Override
      public void onMessageReceived(RemoteMessage remoteMessage) {
          //super.onMessageReceived(remoteMessage);
          Log.d("From: " , remoteMessage.getFrom());
          if(remoteMessage.getNotification() != null){
              String title = remoteMessage.getNotification().getTitle();
              String body = remoteMessage.getNotification().getBody();
              Log.d("title: ", title);
              Log.d("body: ", body);
              sendNotification(title,body);
  
          }
  
      }
  
      @Override
      public void onNewToken(String s) {
          Log.d("NewToken: ",s);
  
          sendRegistrationToSever(s);
      }
  
      private void handleNow(){
  
      }
      private void sendRegistrationToSever(String token){
  
      }
  
      private void sendNotification(String title, String body){
          String channelId = getString(R.string.defaul_notification_channel_id);
          Intent intent = new Intent(this, MainActivity.class);
          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  
          PendingIntent pendingIntent = (PendingIntent) PendingIntent.getActivities(this, 0, new Intent[]{intent}, PendingIntent.FLAG_ONE_SHOT);
  
          Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  
          NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId)
                  .setSmallIcon(R.drawable.ic_launcher_foreground)
                  .setContentTitle(title)
                  .setContentText(body)
                  .setAutoCancel(true)
                  .setSound(defaultSoundUri)
                  .setContentIntent(pendingIntent);
  
          NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O) {
              NotificationChannel notificationChannel = new NotificationChannel(channelId,"Firebase Noti", NotificationManager.IMPORTANCE_DEFAULT);
              notificationManager.createNotificationChannel(notificationChannel);
  
          }
          notificationManager.notify(0, builder.build());
      }
  }
  </code></pre>
  
  <p>My Manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="dfk.example.com.firebasenotificationtry3"&gt;
      &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
      &lt;uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/&gt;
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:roundIcon="@mipmap/ic_launcher_round"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity android:name=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;service android:name=".Service.MyFirebaseMessagingService"
              android:exported="false"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.google.firebase.MESSAGING_EVENT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/service&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <pre><code>apply plugin: 'com.android.application'
  apply plugin: 'com.google.gms.google-services'
  
  android {
      compileSdkVersion 28
      defaultConfig {
          applicationId "dfk.example.com.firebasenotificationtry3"
          minSdkVersion 16
          targetSdkVersion 28
          versionCode 1
          versionName "1.0"
          testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  dependencies {
      implementation fileTree(dir: 'libs', include: ['*.jar'])
      //noinspection GradleCompatible
      implementation 'com.android.support:appcompat-v7:28.0.0'
      implementation 'com.android.support.constraint:constraint-layout:1.1.3'
      implementation 'com.google.firebase:firebase-messaging:18.0.0'
      implementation 'com.google.firebase:firebase-core:16.0.1'
      testImplementation 'junit:junit:4.12'
      androidTestImplementation 'com.android.support.test:runner:1.0.2'
      androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
  }
  </code></pre>
  
  <pre><code>// Top-level build file where you can add configuration options common to all sub-projects/modules.
  
  buildscript {
      repositories {
          google()
          jcenter()
  
      }
      dependencies {
          classpath 'com.android.tools.build:gradle:3.3.2'
          classpath 'com.google.gms:google-services:4.1.0'
  
          // NOTE: Do not place your application dependencies here; they belong
          // in the individual module build.gradle files
      }
  }
  
  allprojects {
      repositories {
          google()
          jcenter()
  
      }
  }
  
  task clean(type: Delete) {
      delete rootProject.buildDir
  }
  </code></pre>