我的App中的PendingIntent存在问题。
我将GCM消息从我的服务器发送到我的应用程序。当用户点击通知时,将创建一个新的PendingIntent,将用户移动到" AlertActivity",开始倒计时
目前所有这些都很好。
现在问题是,当用户关闭应用程序并重新打开它时。 倒计时正在运行时,我想再次将用户重定向到AlertActivity。
这怎么可能?
我用以下内容启动Intent:
private void sendNotification(String msg) {
Intent resultIntent = new Intent(this, AlertActivity.class);
resultIntent.putExtra("msg", msg);
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0,
resultIntent, 0);
NotificationCompat.Builder mNotifyBuilder;
NotificationManager mNotificationManager;
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotifyBuilder = new NotificationCompat.Builder(this)
.setContentTitle("Alert")
.setContentText("You've received new message.")
.setSmallIcon(R.drawable.ic_launcher);
// Set pending intent
mNotifyBuilder.setContentIntent(resultPendingIntent);
// Set Vibrate, Sound and Light
int defaults = 0;
//defaults = defaults | Notification.DEFAULT_LIGHTS;
//defaults = defaults | Notification.DEFAULT_VIBRATE;
// defaults = defaults | Notification.DEFAULT_SOUND;
Notification notification = mNotifyBuilder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.alarm);
notification.defaults |= Notification.DEFAULT_VIBRATE;
mNotifyBuilder.setDefaults(defaults);
// Set the content for Notification
mNotifyBuilder.setContentText("New message from Server");
// Set autocancel
mNotifyBuilder.setAutoCancel(true);
// Post a notification
mNotificationManager.notify(notifyID, notification);
}