I use FirebaseMessagingService.

In the FirebaseMessagingService.onMessageReceived method, I create a Notification and set it to setContentIntent . If the application is in the foreground, the push transition works correctly. But if the application is in the background or closed, then clicking on the button throws on the main activity of the application.

How to make the transition by pushing to the specified activity in all cases?

Callback method code for FirebaseMessagingService.onMessageReceived :

 @Override public void onMessageReceived(RemoteMessage remoteMessage) { Log.d(TAG, "body" + remoteMessage.getNotification().getBody()); if (remoteMessage.getData().size() > 0) { Log.d(TAG, "Message data payload: " + remoteMessage.getData()); } Map<String, String> data = remoteMessage.getData(); String type = data.get("type"); Intent intent; PendingIntent pendingIntent; switch (type) { case "telecast": String title = data.get("title"); int channelId = Integer.valueOf(data.get("channel_id")); int programId = Integer.valueOf(data.get("program_id")); boolean isFavorite = data.containsKey("favorite") ? Boolean.valueOf(data.get("favorite")) : false; intent = ProgramActivity.newIntent(this, title, channelId, programId, TAG_PROGRAM, isFavorite, 0); intent.setPackage("ru.arealidea.vsetv.App"); break; case "film": int id = Integer.valueOf(data.get("id")); intent = new Intent(this, FilmsInfoActivity.class).putExtra("id", id); break; case "podcast": int podcast_id = Integer.valueOf(data.get("podcast_id")); int episode_id = Integer.valueOf(data.get("episode_id")); intent = new Intent(this, PodcastInfoActivity.class).putExtra("id", podcast_id); break; default: return; } pendingIntent = PendingIntent.getActivity(this, remoteMessage.hashCode(), intent, 0); Resources resources = getResources(); Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Notification notification = new NotificationCompat.Builder(this) .setTicker(remoteMessage.getNotification().getBody()) .setSmallIcon(R.mipmap.app_icon) .setContentTitle(resources.getString(R.string.app_name)) .setContentText(remoteMessage.getNotification().getBody()) .setContentIntent(pendingIntent) .setAutoCancel(true) .setSound(defaultSoundUri) .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 }) .setLights(Color.RED, 3000, 3000) .build(); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(remoteMessage.hashCode(), notification); } 

Manifest activities:

 <activity android:name=".App.Activity.ProgramActivity"/> <activity android:name=".App.Activity.PodcastInfoActivity"/> <activity android:name=".App.Activity.FilmsInfoActivity"/> 

    0