Lost in PendingIntent fields
I am a bit lost with PendingIntent.
As far as I could understand, it's a Token given to the OS to perform later (hence pending) operations.
I have an activity that launched a service. The service, occasionally creates a notification. What I am trying to do, as the simplest of all, is to bring the activity to the front.
I am not sure where and how I create and to whom I send the PendingActivity.
- If I create it within the Activity, I need to send it to the service - HOW?
- If I create it within the service, how would the context be to call the activity? are these the same? - I though these are the same, as how the OS works, but it did not work for me.
Here are some code lines
This is not working btw StartService gets an Intent. This code is in my activity
Intent intent = new Intent(this, NeglectedService.class);
// The PendingIntent to launch our activity if the user selects this notification
PendingIntent contentIntent = PendingIntent.getActivity(this,
0,
intent,
PendingIntent.FLAG_ONE_SHOT);
startService(contentIntent);
So, the correct one is
Intent intent = new Intent(this, NeglectedService.class);
startService(contentIntent);
So I think to make the pending intent in my service, but this didn't work for开发者_Go百科 me, as I am not sure how to reuse/use the intent
Notification notification = new Notification(R.drawable.icon,
extra,
System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(this,
0,
intent, // not sure what intent to use here !!!!
PendingIntent.FLAG_ONE_SHOT);
notification.setLatestEventInfo(getApplicationContext(), contentTitle, contentText, contentIntent);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.FLAG_INSISTENT;
mNotificationManager.notify(id, notification);
solved What needed to be done, is use the Neglected.class in the intent.
精彩评论