Saariko
Saariko

Reputation: 1703

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.

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 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);

Upvotes: 0

Views: 329

Answers (1)

Saariko
Saariko

Reputation: 1703

solved What needed to be done, is use the Neglected.class in the intent.

Upvotes: 1

Related Questions