mercredi 27 mai 2015

How to set two intents in a pending intent

Is possible to set more than one intent for be launched when, in example, the user clicks an notification.

Let me explain my concrete problem:

I have an app with notifications. Each notification open a different Activity (with different extras too).

Now I want to extract info about the notifications usage. So, every time a notification gets open I'd like to launch a Service with some extras.

I'd like to implement that without modifying the existing activities, since they are not "guilty" of the change.

Ideally the pseudocode could be something like that:

Intent originalActivityIntent=...;
Intent notificationsAnalyticsIntent=getRegisterNotificationClick(notificationId,username);
PendingIntent pi= PendingIntent.multiple(
                                   context,
                                   originalActivityIntent,
                                   notificationsAnalyticsIntent)

Having both intents launched when the notification is clicked.

Writting some kind of service/broadcast receiver could be pretty complex since I would need to handle the different params for each Activity.

Any ideas of how to keep this clean?

Aucun commentaire:

Enregistrer un commentaire