我在收到GCM推送通知消息后创建通知。一切都完成了。但是当我点击通知时,有时它无法启动(PendingIntent)。大多数情况下,问题出现在我接收到通知后不久点击时。PendingIntent实际上是我的第一个登录页面。这是源代码...
public void createNotification(Context context, String message) {
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon,
"My notification", System.currentTimeMillis());
// Hide the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL ;
Intent intent;
intent = new Intent(context, Login.class);
intent.putExtra("pushNoti", "pushNoti");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, "my Alert",
message, pendingIntent);
notification.defaults = Notification.DEFAULT_SOUND;
notificationManager.notify(0, notification);
}
这里的上下文是从GCM onMessage(Context context,Intent intent)中获取的。
有人能帮我吗?