ila*_*lan 4 android android-activity android-pendingintent google-cloud-messaging
如果我有一个被用户关闭的活动(用户按下主页,所以应用程序仍在应用程序堆栈中),然后他收到通知,当他按下它时,我开始一个活动,现在同一个活动打开了两次。我怎样才能防止这种情况发生?
我的代码:
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
NotificationManager mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.logo)
.setContentTitle("Title")
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setAutoCancel(true)
.setLights(GCMSIntentService.PURPLE, 500, 500)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(1, mBuilder.build());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2195 次 |
| 最近记录: |