通知を送信する通知関数を作成しました。ユーザーがトップバーの通知をクリックすると、定義されたアクティビティに切り替わります。私のコードは私が望むことをしました。しかし問題がある。
3 つのアクティビティ (A、B、C) があり、ユーザーがトップ バーの通知をクリックすると、A に切り替わるとします。
流れは、
(1) ユーザーがAを開く
(2) AのボタンをクリックしてBに切り替える
(3) トップバーの通知をクリック
(4) Aに切り替える (大丈夫)
(5) 再度、aをクリック
(6) ホームボタンを押してアプリを非表示にします
(7) ホームボタンを長押しして、アプリのアイコンをクリックします(8) A
に切り替えます (??? アクティビティにいるので、B に切り替える必要があります) B!)
---- ホームボタンを長押ししてアプリに切り替えると、アクティビティ A に切り替わらないようにするにはどうすればよいですか? ありがとう!
コード スニペットは次のとおりです。
int notificationCounter = 0;
private void displayNotificationMessage(String title, String message, int notification_id, String fromUser, boolean vibrate, boolean playSound, String notificationActionStr)
{
if (receiverMessageBroadcast || !currentTargetUser.equals(fromUser))
{
Intent intent = new Intent();
intent.setClass(this, MainActivity.class);
//intent.setAction(notificationAction + "_" + System.currentTimeMillis());
Bundle bundle = new Bundle();
bundle.putInt("notificationAction", 1);
bundle.putString("targetUser", fromUser);
intent.putExtras(bundle);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
Notification notification = new Notification(R.drawable.notification, message, System.currentTimeMillis());
notification.setLatestEventInfo(this, title, message, PendingIntent.getActivity(this.getBaseContext(), notificationCounter, intent, PendingIntent.FLAG_UPDATE_CURRENT));
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
if (playSound)
notification.defaults |= Notification.DEFAULT_SOUND;
if (vibrate)
notification.vibrate=new long[] {100L, 100L, 200L, 500L};
notification.ledARGB = Color.WHITE;
notification.ledOnMS = 1500;
notification.ledOffMS = 1500;
notificationMgr.notify(fromUser, 0, notification);
notificationCounter++;
}
}