Here is my code of notification. Actually, I'm getting the notification perfectly but when I click on the notification in a phone the app will open directly (when the app is in the background or killed). When the app is in the foreground, the ResultActivity will open correctly when I click on notification but the data is not showing over there. 
Please check my code and let me know what I did wrong.
FirebaseMessagingService.java:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
Map<String, String> data;
String Title, Message, PushType;
String body, title;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Log.e(TAG, "From: " + remoteMessage.getFrom() + "");
    data = remoteMessage.getData();
    JSONObject jsonObject = new JSONObject(data);
    try {
        Log.e("data", jsonObject.toString());
        body = jsonObject.getString("body");
        title = jsonObject.getString("title");
        Log.e("body", body);
        Log.e("title", title);
    } catch (JSONException e) {
        Log.e("exception>>>", e.toString() + "");
        e.printStackTrace();
        body = remoteMessage.getNotification().getBody();
        Log.e("body>>>", body + "");
    }
    sendNotification(body, title);
}
private void sendNotification(String message, String title){
    Log.e("message>>>", message + "");
    Intent intent = new Intent(this, ResultActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("body",message);
    intent.putExtra("title",title);
    int requestCode = 0;
    PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_ONE_SHOT);
    Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.fc)
            //.setSmallIcon(getNotificationIcon())
            .setContentText(message)
            .setColor(ContextCompat.getColor(this, R.color.colorPrimary))
            .setAutoCancel(true)
            .setSound(sound)
            .setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, noBuilder.build()); //0 = ID of notification
}
ResultActivity.java:
public class ResultActivity extends Activity {
    private TextView Title,Message ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notification_view);
        Title=(TextView)findViewById(R.id.title);
        Message=(TextView)findViewById(R.id.message);
        if(getIntent().getExtras()!=null)
        {
            for(String key : getIntent().getExtras().keySet())
            {
                if(key.equals("title"))
                    Title.setText(getIntent().getExtras().getString(key));
      else if(key.equals("message"))
                Message.setText(getIntent().getExtras().getString(key));
            }
        }
    }
}
activity_notification_view.xml:
<TextView
    android:layout_marginTop="50dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/title"
    android:hint="title"
    android:gravity="center" />
<TextView
    android:hint="message"
    android:layout_marginTop="20dp"
    android:gravity="center"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/message" />
 
     
     
    