I have an unusual problem where my push notifications are using data from older push notifications, I think. My app has a list of companies and I use push notifications with data so that when the user clicks on the notification it takes them to that company in my app. While testing, the first message I send works fine and takes me to the right company. When I send another message that is supposed to go to a different company, it goes to the first one. I know that the app is receiving the correct information, because when I log the company ID it matches what its supposed to be. But when the app is opened from by clicking the notification, the company ID that shows up in the log is not the right one.
here is the code that handles the notification
private void sendNotification(String title, String msg, String cat, String comp) {
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
Log.i("Send notif",""+comp);
Intent launch = new Intent(this, AccountSetup.class);
launch.putExtra("cat", cat).putExtra("comp", comp);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
launch, 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
this is working as expected, here is the code i have for pulling the information out onCreate()
Intent thispage = getIntent();
if(thispage.getStringExtra("comp") != null ) {
Log.i("mainactivity extras","received cat " + thispage.getIntExtra("cat", 11) + " comp " + thispage.getStringExtra("comp"));
mainPage.putExtra("currentLocation", user._Location)
.putExtra("selectedCategory", thispage.getIntExtra("cat", 11))
.putExtra("selectedCompany", -1)
.putExtra("companyID", thispage.getStringExtra("comp"));
}
this is where im having the problem, when the activity launches, it still has the old company ID, regardless of what push notification message I clicked.
Am I missing something? the title and body of the message are correct, and the log shows that the company id is right too, just when I click it the intent extras are only showing whatever was sent in the first message.