我正在尝试使用谷歌实施的代码,但似乎我错过了一些东西。这是代码
int notificationId = 001;
// Build intent for notification content
Intent viewIntent = new Intent(this, ViewEventActivity.class);
viewIntent.putExtra(EXTRA_EVENT_ID, eventId);
PendingIntent viewPendingIntent =
PendingIntent.getActivity(this, 0, viewIntent, 0);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_event)
.setContentTitle(eventTitle)
.setContentText(eventLocation)
.setContentIntent(viewPendingIntent);
// Get an instance of the NotificationManager service
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(this);
// Build the notification and issues it with notification manager.
notificationManager.notify(notificationId, notificationBuilder.build());
当我运行它时,我看到我的设备获得通知,但是当我点击通知时我的ViewEventActivity类没有被激活。我试图将FLAG_ACTIVITY_NEW_TASK标志添加到我的viewIntent(这是getActivity()方法定义中的一个提示),但没有运气。任何帮助将不胜感激。
答案 0 :(得分:0)
我的问题是我错过了清单中我的活动ViewEventActivity的声明。
<activity
android:name=".ViewEventActivity" />
当找不到引用ViewEventActivity.class时,应用程序没有崩溃,这很奇怪。