有关服务活动的意图附加内容>>

问题描述 投票:0回答:1

我有一个活动和一项服务。在该服务中,我创建了一个通知,如果点击了该通知,它将打开活动。

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个额外的奖励,但是我在通知意图上添加了两个额外的奖励。任何帮助或意义??

感谢

我有一个活动和一项服务。在该服务中,我创建了一个通知,如果点击了该通知,它将打开活动。 Intent notificationIntent =新的Intent(this,MainActivity.class); ...

android android-intent android-service
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.