Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: background service to send a notification and when the user clicks the notification it must launch the appropriate activity

chitraksh bairathee:

I am developing a small app in which I want a background service to send a Notification and when the user clicks the notification it must launch the appropriate activity. I am posting the code here for the notification and my problem is that the notification gets displayed on the status bar but when i click it it does not launch the activity. Can somebody suggest where I am going wrong. Please help.


Intent intent = new Intent(this, IncidentDetail.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

Bundle extras = new Bundle();
extras.putString("BodyText", "hi"+messageBody);
intent.putExtras(extras);

PendingIntent pendingIntent = PendingIntent.getService(this,0 /* Request code */
, intent,PendingIntent.FLAG_UPDATE_CURRENT);
//here i tried with both getService and getActivity
/*PendingIntent pendingIntent = PendingIntent.getActivity(this,0
, intent,PendingIntent.FLAG_UPDATE_CURRENT);*/

Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(Title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
;

NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

Below is my manifest file







android:name=".IncidentDetail"
android:label="@string/title_activity_incident_detail"
android:exported="true"
android:launchMode="singleTop">




Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: background service to send a notification and when the user clicks the notification it must launch the appropriate activity

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×