Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch an activity when notification is clicked?

I have a strange problem in my app in android. I have done a notification and I want to launch a new activity when notification is clicked. The problems is that when I click on notification nothing happens, and I have no idea where is the problem? Can anyone help me?Here is my code :

notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence NotificationTicket = "Notification";
CharSequence NotificationTitle = "Notification";
CharSequence NotificationContent = "Test";
long when = System.currentTimeMillis();

Notification notification = new Notification(R.drawable.icon,
NotificationTicket, when);

Context context = getApplicationContext();

Intent notificationIntent = new Intent(this, ShopsOnMap.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);

notification.setLatestEventInfo(context, NotificationTitle, NotificationContent, contentIntent); 
notificationManager.notify(NOTIFICATION_ID, notification);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP); 
like image 620
Gaby Avatar asked Dec 09 '22 08:12

Gaby


1 Answers

I had the same problem and then realized that I hadn't declared my new activity in the Manifest.

<activity
        android:name=".YourActivityHere">
        </activity>
like image 200
easycheese Avatar answered Dec 11 '22 23:12

easycheese