【发布时间】:2015-11-13 06:16:45
【问题描述】:
我正在开发一个 android 应用程序,我也实现了 GCM 推送通知,并且每个通知 id 都不同,问题是当我有 n 个推送通知并且应用程序不在后台时,当我第一次单击通知时它将打开活动。然后我再次从后台清除应用程序实例并单击另一个推送通知它不会打开应用程序。
Intent intent = new Intent(this, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(intent);
long[] vibrate = {0, 100, 200, 300};
Uri notification = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
PendingIntent contentIntent = stackBuilder.getPendingIntent(0,
PendingIntent.FLAG_UPDATE_CURRENT
| PendingIntent.FLAG_ONE_SHOT);
Bitmap largIcon = BitmapFactory.decodeResource(this.getResources(),
R.mipmap.ic_launcher);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setSmallIcon(R.mipmap.small_icon_notification)
.setContentTitle(getResources().getString(R.string.app_name))
.setLargeIcon(largIcon)
.setSound(notification)
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setContentText(msg). setSound(notification)
.setStyle((new NotificationCompat.BigTextStyle()).bigText(msg)) .setAutoCancel(true);
mBuilder.setVibrate(vibrate);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify((int) System.currentTimeMillis(), mBuilder.build());
【问题讨论】:
-
我认为您不应该将 System.currentTimeMillis() 转换为 int。请改用随机数生成器。
-
如你所说,我更改了通知 ID。但结果是一样的
-
你能用你的改变更新代码吗?
标签: android android-activity push-notification google-cloud-messaging