title: intent to specific activity when push notification clicked in.
body: <p>Not opening specific activity on notification click when the app is in background/not running</p>
  
  <p>The notification-click starts specified activity only when the app is opened up and the notification-click is performed. If the app is in background/not running and the notification-click is performed, the application's MainActivity opens up. In short, it is like the app opens normally following the activity stack instead of opening the specified activity in the PendingIntent.</p>
  
  <p><strong>Firebase Instance Id Service:</strong></p>
  
  <pre><code>package com.example.tamzid.pushnotification;
  
   import android.util.Log;
   import com.google.firebase.iid.FirebaseInstanceId;
   import com.google.firebase.iid.FirebaseInstanceIdService;
  
   public class MyAndroidFirebaseInstanceIdService extends 
  FirebaseInstanceIdService {
  
  private static final String TAG = "MyAndroidFCMIIDService";
  
  @Override
  public void onTokenRefresh() {
      //Get hold of the registration token
      String refreshedToken = FirebaseInstanceId.getInstance().getToken();
      //Log the token
      Log.d(TAG, "Refreshed token: " + refreshedToken);
  }
  private void sendRegistrationToServer(String token) {
      //Implement this method if you want to store the token on your server
  }
  }
  </code></pre>
  
  <p><strong>Firebase Message Service:</strong></p>
  
  <pre><code> package com.example.tamzid.pushnotification;
  
   import android.app.NotificationManager;
   import android.app.PendingIntent;
   import android.content.Context;
   import android.content.Intent;
   import android.media.RingtoneManager;
   import android.net.Uri;
   import android.support.v4.app.NotificationCompat;
   import android.util.Log;
   import com.google.firebase.messaging.FirebaseMessagingService;
   import com.google.firebase.messaging.RemoteMessage;
  
   public class MyAndroidFirebaseMsgService extends FirebaseMessagingService     
  {
  private static final String TAG = "MyAndroidFCMService";
  @Override
  public void onMessageReceived(RemoteMessage remoteMessage) {
      //Log data to Log Cat
      Log.d(TAG, "From: " + remoteMessage.getFrom());
      Log.d(TAG, "Notification Message Body: " +     
  remoteMessage.getNotification().getBody());
      //create notification
      createNotification(remoteMessage.getNotification().getBody());
  }
  
  private void createNotification( String messageBody) {
      Intent intent = new Intent( this , ResultActivity. class );
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      PendingIntent resultIntent = PendingIntent.getActivity( this , 0, 
  intent,
              PendingIntent.FLAG_ONE_SHOT);
  
      Uri notificationSoundURI = 
  RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
      NotificationCompat.Builder mNotificationBuilder = new 
  NotificationCompat.Builder( this)
              .setSmallIcon(R.mipmap.ic_launcher)
              .setContentTitle("Android Tutorial Point FCM Tutorial")
              .setContentText(messageBody)
              .setAutoCancel( true )
              .setSound(notificationSoundURI)
              .setContentIntent(resultIntent);
  
      NotificationManager notificationManager =
              (NotificationManager)  
  getSystemService(Context.NOTIFICATION_SERVICE);
  
      notificationManager.notify(0, mNotificationBuilder.build());
   }
  }
  </code></pre>
  
  <p><strong>AndroidManifest.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.tamzid.pushnotification"&gt;
  
  &lt;application
      android:name="android.support.multidex.MultiDexApplication"
      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;activity android:name=".ResultActivity"&gt;&lt;/activity&gt;
      &lt;service android:name=".MyAndroidFirebaseMsgService"&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=".MyAndroidFirebaseInstanceIdService"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.firebase.INSTANCE_ID_EVENT" 
  /&gt;
          &lt;/intent-filter&gt;
      &lt;/service&gt;
  
  &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>