Intent 附加服务-Activity

Intent extras on Service-Activity

我有一个 Activity 和一个服务。在该服务中,我创建了一个通知,如果点击它,它会打开 activity。

Intent notificationIntent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
        Bundle extras = new Bundle();
        extras.putString(MainActivity.SELECTED_FRAGMENT,"GameFragment");
        extras.putParcelable(GameFragment.GAME_ARG,route);
        notificationIntent.putExtras(extras);
        Log.d("JON notification intent","Elements: " + notificationIntent.getExtras().size());
        PendingIntent pendingIntent =
                PendingIntent.getActivity(this, 0, notificationIntent, 0);
        Notification notification =
                new Notification.Builder(this, channelId)
                        .setContentTitle(getText(R.string.app_name))
                        .setContentText(getText(R.string.app_name))
                        .setSmallIcon(R.drawable.ic_stat_orbel_jokuek)
                        .setContentIntent(pendingIntent)
                        .setTicker(getText(R.string.app_name))
                        .build();

        startForeground(1, notification);

问题是在 Activity 的 onCreate 方法上:

if (getIntent().getExtras() != null) {
        Log.d("JON intent size","Elements: " + getIntent().getExtras().size());
    }

我只得到 1 个额外的,但我在通知意图上放了两个额外的。任何帮助或意义?

谢谢

答案是在 PendingIntent.getActivity() 函数上使用 PendingIntent.FLAG_UPDATE_CURRENT。