Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confusing behavior when starting new activity with PendingIntent

Tags:

android

I am using BroadCast Listener to listen to incoming phone stat then pushing a Notification like this:

    CharSequence contentTitle = "Contact: " + number;
    CharSequence contentText = "Call From: " + number;
    Intent notificationIntent = new Intent(context, CallHandler.class);

    notificationIntent.putExtra(KEYS.NUMBER, number);
    notificationIntent.putExtra(KEYS.STATE, stat);
    notificationIntent.putExtra(KEYS.NAME, name);
    notificationIntent.putExtra(KEYS.DURATION, duration);
    notificationIntent.putExtra(KEYS.START_TIME, startTime);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    notif.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

    notif.flags |= Notification.FLAG_AUTO_CANCEL;

    notificationManager.notify((int) System.currentTimeMillis(), notif);

So when there are multiple calls, I expect to have multiple call notification and when I click each notification, I expect to start an activity with the attached parameters. However, I can see that the Activities that starts later, gets the Intent of the previous call.

Here is how I am looking into intent from the Activity

        Bundle extras = getIntent().getExtras();
    String number = extras.getString(KEYS.NUMBER);
    // String state = extras.getString(KEYS.STATE);
    long duration = extras.getLong(KEYS.DURATION);

    Date start = getStartDate();
    ((TextView) findViewById(R.id.subject)).setText("");
    ((TextView) findViewById(R.id.start_time)).setText(tf.format(start));
    ((TextView) findViewById(R.id.end_time)).setText(tf
            .format(getEndDate()));
    ((TextView) findViewById(R.id.caller_number)).setText(number);
    ((TextView) findViewById(R.id.notes)).setText(getNotesDefaultContent(
            number, duration, start));

How can I keep the intents separately call independent activity?

like image 971
Sajid Avatar asked Jan 01 '26 01:01

Sajid


1 Answers

Try this:

PendingIntent.getActivity(context, 0 , notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

Notice the last parameter of the PendingIntent.getActitity method. If you'd like to know which FLAG you should use, see the API documents - [http://developer.android.com/reference/android/app/PendingIntent.html#getActivity(android.content.Context, int, android.content.Intent, int)][1]

[1]: http://developer.android.com/reference/android/app/PendingIntent.html#getActivity(android.content.Context, int, android.content.Intent, int)

~Dolph~

like image 106
Dolph Avatar answered Jan 02 '26 17:01

Dolph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!