user533844
user533844

Reputation: 2063

Android notification click

I am running a service which is popping notification on getting a new task. If I close my app it's running in the background and pop up a notification. What I would like to do is, when I click on that notification, open the app. Can I do that ? How ?

Upvotes: 0

Views: 197

Answers (1)

Chris
Chris

Reputation: 23171

You can do this by adding an intent to your notification:

    Intent notificationIntent = new Intent(context, YourAppActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
            notificationIntent, 0);
    notification.setLatestEventInfo(context, "headline", "body msg", contentIntent);
    notifcationMgr.notify(id, notification);

Just replace YourAppActivity with the activity you want to launch.

Upvotes: 3

Related Questions