少し問題があり、多くの場所を調べましたが、答えが見つからないようです。
サービスがあります。このサービスは、サイトの通知をチェックし、ユーザーに新しい通知を警告します。ユーザーがこの通知をクリックすると、アクティビティが表示されます (これを CommentActivity と呼びます)。
ただし、アプリ内の通知をクリックしても何も起こりません。アプリの外で通知をクリックすると、アプリが閉じられる前に表示されていた最後のアクティビティが開きます。
通知を表示するための私のコードは次のとおりです。
Notice n; //Notification from site
....
Intent nIntent = new Intent(Intent.ACTION_MAIN);
nIntent.setClass(getApplicationContext(), CommentActivity.class);
nIntent.putExtra("activity_id", n.getFeedID());
nIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext(), 0, nIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(FlankNotificationService.this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(n.getTitle())
.setContentText(n.getText())
.setContentInfo(arg0.getNotificationAmount() + " notification" + (arg0.getNotificationAmount() == 1 ? "." : "s."))
.setContentIntent(pIntent);
Notification mm = mBuilder.getNotification();
mm.flags = Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL;
mm.tickerText = n.getText();
....
mNM.notify(1558, mm);
したがって、CommentActivity を開く代わりに、アプリを再開するか (アプリが開いていない場合)、何も実行しません (アプリが開いている場合)。
ありがとうございました。
編集1:
Intent.FLAG_ACTIVITY_REORDER_TO_FRONT フラグを Intent に追加しました。それでも問題は解決しません。
編集2:
私は自分の問題の原因を見つけました (これはかなりばかげた原因でした)。CommentActivity の開始時に、savedInstance または Intent.getExtra のいずれからもデータが渡されない場合は、終了します。最初にこれを思いつかなかったのは、遷移さえ示していなかったからです。Intent.getExtra の問題を修正した後、動作するようになりました。すべての回答に感謝します。