알림이 이전 의도 엑스트라를 전달 함 |= Notification.DEFAULT_VIBRATE;

이 코드를 통해 BroadcastReceiver 내부에 알림을 작성 중입니다.

String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
        int icon = R.drawable.ic_stat_notification;
        CharSequence tickerText = "New Notification";
        long when = System.currentTimeMillis();

        Notification notification = new Notification(icon, tickerText, when);
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        long[] vibrate = {0,100,200,200,200,200};
        notification.vibrate = vibrate;
        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        CharSequence contentTitle = "Title";
        CharSequence contentText = "Text";
        Intent notificationIntent = new Intent(context, NotificationActivity.class);
        notificationIntent.putExtra(Global.INTENT_EXTRA_FOO_ID, foo_id);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

        int mynotification_id = 1;

        mNotificationManager.notify(mynotification_id, notification);

알림을 클릭하면 NotificationActivity가 열리고 활동 내부에서 인 텐트 번들 (예 : 1)에서 foo_id를 검색 할 수 있습니다

그러나 다른 알림이 트리거되고 다시 클릭하면 액티비티는 여전히 인 텐트 번들에서 “오래된”값 (1)을받습니다. clear ()로 번들을 지우려고했지만 동일한 효과가 나타납니다. 내 코드에 sth가 잘못되었다고 생각합니다.



답변

보류중인 강도에 대해 동일한 요청 코드를 보내고 있습니다. 이것을 변경하십시오 :

PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

에:

PendingIntent contentIntent = PendingIntent.getActivity(context, UNIQUE_INT_PER_CALL, notificationIntent, 0);

동일한 매개 변수를 보내면 의도가 작성되지 않습니다. 그들은 재사용된다.


답변

또는 다음 코드를 사용하여 PendingIntent를 생성 할 수 있습니다.

PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

에 대한 문서에서 PendingIntent.FLAG_UPDATE_CURRENT:

설명 된 PendingIntent가 이미 존재하는 경우이를 유지하면서 추가 데이터를이 새로운 Intent에있는 것으로 대체하십시오. 엑스트라 만 변경되는 인 텐트를 생성하고 이전 PendingIntent를받은 엔터티가 명시 적으로 제공되지 않은 경우에도 새 엑스트라로이를 시작할 수 있는지에 대해서는 신경 쓰지 않아도됩니다.


답변

동일한 ID를 전달하고 있습니다. 이런 상황에서는 다음과 같이 고유 한 ID를 만드십시오.

int iUniqueId = (int) (System.currentTimeMillis() & 0xfffffff);

그리고 이것을 다음과 같이 넣으십시오.

PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(),iUniqueId, intentForNotification, 0);


답변

오랜 시간이 지난 후 가장 좋은 방법을 찾고있는 사람은 PendingIntent.FLAG_UPDATE_CURRENT 를 아래 표시된 마지막 인수로 전달해야 합니다.

PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

새로운 고유 ID를 제공 할 필요조차 없습니다.

처음이 아닌 다음에이 작업을 수행해야합니다.


답변

모든 알림의 요청 코드는 0입니다. 다음 줄을 변경하십시오.

PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

와:

PendingIntent contentIntent = PendingIntent.getActivity(context, new Random().nextInt(), notificationIntent, 0);


답변

다른 옵션을 추가하고 싶었습니다.

 PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);


답변