intent extras are duplicated when using FLAG_UPDATE_CURRENT in PendingIntent when creating android notifications

前端 未结 1 1345
广开言路
广开言路 2020-12-24 03:01

I want to create several notifications that launches an activity (or refresh it) to display a product description.

Notification notification = new Notificati         


        
1条回答
  •  爱一瞬间的悲伤
    2020-12-24 03:40

    but it doesn't work as it should

    Yes, it does.

    If I create 2 notifications, they both have the same 'saleid' extra which is the latest one.

    This is precisely what the documentation says is supposed to happen.

    How can I make more than one notification with differents 'saleid' extra?

    Option #1: Put a different action string in each of your Intents. This will make them different (from the standpoint of filterEquals()) and give them separate PendingIntents. However, since you are specifying the component in the Intent (MainApplication.class), the action will not affect how the Intent is routed.

    Option #2: Use a different requestCode (2nd parameter) on your getActivity() calls. While this is documented as "currently not used", it does result in different PendingIntent objects being returned. However, since this behavior is undocumented, it may change in the future.

    0 讨论(0)
提交回复
热议问题