Search code examples
androidandroid-intentnotificationsandroid-pendingintent

How to make a notification tap in Android perform multiple actions?


I have set up a notification that opens a website when you tap it. Here's the part of the code that does it.

Intent resultIntent = new Intent(Intent.ACTION_VIEW);
resultIntent.setData(Uri.parse(m.msg.url));

PendingIntent pending = PendingIntent.getActivity(context, 0,
        resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notif.setContentIntent(pending);

The notification corresponds to a notification in a website, which also corresponds to a message in that website. So when you tap the (Android) notification, you go to that website. But I also want to remove the (website) notification by sending a GET request. I already have set a method that does that:

m.delete();

However, I can't find a way to execute both actions at once. The intent should open m.msg.url and execute m.delete(). I have searched for information on Intents and Services but I'm new to Android programming and I don't quite understand how it works. I'd really appreciate any help or guidance.

Thanks for reading.


Solution

  • Create an Activity or Service that performs the GET then immediately starts the activity you really want to start. Use that as the PendingIntent instead.