【发布时间】:2017-06-08 09:01:12
【问题描述】:
我正在尝试在单击通知时启动 Activity,但它从未启动。下面是我发送通知的代码:
Intent notificationIntent = new Intent(this, MainActivity.class);
notificationIntent.putExtra("Notification", type);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pIntent = PendingIntent.getActivity(this, 0,notificationIntent, 0);
Notification n = new Notification.Builder(this)
.setContentTitle(title)
.setContentText(type)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pIntent)
.build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, n);
我从来没有在点击通知时接到该活动的电话。
【问题讨论】:
-
你在 AndroidManifest 中声明了这个服务类吗?
-
我正在通过 FCM 接收通知,通知出现在通知栏中,但单击它永远不会调用活动。 Activity 已注册并在应用中运行。
-
getAcitivy中的最后一个参数是标志,我认为它不应该是 0 -
我已尝试放置所有标志但没有成功 FLAG_UPDATE_CURRENT
标签: android android-activity android-notifications android-pendingintent