【发布时间】:2019-09-27 10:45:41
【问题描述】:
我有一个活动和一个服务。在服务中,我创建了一个通知,如果点击它,它会打开活动。
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 个,但我在通知意图上添加了两个额外。有什么帮助或意义吗??
谢谢
【问题讨论】:
-
我发现你的代码有问题
-
任何评论表示赞赏。
标签: android android-intent android-service