tags:

views:

13

answers:

1

Is there a way for the sender of a Notification to know when that Notification is delivered to the receiver? i.e. Some method that can check if a the user has clicked on a given Notification.

What I'm trying to accomplish is this: Have my Service send a notification with a PendingIntent to start ActivityA. But if the user starts ActivityA without clicking on the Notification, I would like the service to cancel the Notification and send a direct Intent to ActivityA

+1  A: 

Your flow does not make a lot of sense to me. If the user opens ActivityA, why would you want to open another instance of ActivityA? I'm not sure what else "send a direct Intent to ActivityA" would mean. I would think a more conventional pattern would be for ActivityA to cancel the Notification in all cases, and ask the service for the latest data in all cases.

If that pattern is unsuitable for you, then have your Notification use a service PendingIntent. Have your service note that the user clicked on the Notification, then have the service start ActivityA. This gives the same effect for the user (tap on Notification, get ActivityA), but your service finds out about the tap.

Or, use an Intent in the activity PendingIntent that is distinct from the Intent that ActivityA normally starts with. Have ActivityA tell the service, "yo, I gots me an Intent, yo" in all cases. If the service raised a Notification and ActivityA indicates it started with the regular Intent, then tell ActivityA to do something. If the service raised a Notification and ActivityA indicates it started with the Notification's Intent, do something else.

CommonsWare
To clarify, if ActivityA is already opened, service will not open another instance of ActivityA (assuming it sets the correct flags for the StartActivity intent).A "direct intent" means a sendBroadcast() to ActivityA when ActivityA is already active.By service Service "noting" that the user clicked on a notification, do you mean set the PendingIntent to the Service itself?
theactiveactor
" A "direct intent" means a sendBroadcast() to ActivityA when ActivityA is already active" Activities do not listen on broadcasts. An activity can dynamically register a BroadcastReceiver, though. "By service Service "noting" that the user clicked on a notification, do you mean set the PendingIntent to the Service itself?" I have no idea what this sentence means, sorry.
CommonsWare