Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 704
Addev Avatar asked Nov 21 '25 13:11

Addev


1 Answers

No.

The way we solved it is that every Activity in out app extends from some base activity and in each notification we pass an extra in the intent that the base activity handle it.

like image 103
shem Avatar answered Nov 23 '25 03:11

shem