有我的代碼來顯示內容,通知欄重複應用:在MyActivity.class時點擊通知欄
NotificationManager mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MyActivity.class).putExtra("package.notification", 123).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher).setContentTitle("");
// Set Big View style to see full content of the message
NotificationCompat.BigTextStyle inboxStyle =
new NotificationCompat.BigTextStyle();
inboxStyle.setBuilder(mBuilder);
inboxStyle.bigText("");
inboxStyle.setBigContentTitle("");
inboxStyle.setSummaryText("");
// Moves the big view style object into the notification object.
mBuilder.setStyle(inboxStyle);
mBuilder.setContentText(msg);
mBuilder.setDefaults(Notification.DEFAULT_ALL);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
在onStart()
@Override
protected void onStart() {
super.onStart();
if (getIntent().getIntExtra("package.notification", -1) == 123) {
//check in here
}
}
問題MyActitvity活動總是會創建新的,當我點擊通知欄中的通知(如果MyActitvity活動存在,則重複活動)。
我想要打開應用程序(這意味着MyActitvity活動已啓用),而不是創建MyActitvity新功能。
只有當應用程序關閉啓動MyActitvity活動(MyActitvity不活躍)
請給我指教
非常感謝你 – 2015-04-06 03:05:35