3

I have a notification that when pressed should launch an activity that in turn launches a dialog box. That all works, but the dialog box pulls info from the notification thought Intent.putExtra(). The problem is, it always pulls the latest information from the putExtra, so if a user clicks a more recent notification, they get info from the older one. Is there a way to dictate which putExtra goes with which notification?

Here's the code I'm using: ID is an int and UserText is a string:

Intent notificationIntent = new Intent(this, DialogActivity.class);
notificationIntent.putExtra("Text", UserText).putExtra("NotifyID", ID);

And in the DialogActivity

Bundle extras = getIntent().getExtras();
String test;
int NID;
if (extras != null) {
test = extras.getString("Text");
NID = extras.getInt("NotifyID");
}

The problem is that those are always the "Text" and "NotifyID" from the first notification no matter what notification the user selects.

1 Answer 1

3

Use removeExtra. In your case:

Bundle extras = getIntent().getExtras();
String test;
int NID;
if (extras != null) {
    test = extras.getString("Text");
    NID = extras.getInt("NotifyID");
    getIntent().removeExtra("Text");
    getIntent().removeExtra("NotifyID");
}
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.