i am trying to pass some data from my notification intent to one of my activities. but somehow the value is not getting populated correctly.
My notification code from where activity is being called –
Long rowId = intent.getExtras().getLong(TasksDBAdapter.KEY_ROWID);
// Status bar notification Code Goes here.
NotificationManager mgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(this, ReminderModificationActivity.class);
notificationIntent.putExtra(TasksDBAdapter.KEY_ROWID, rowId);
Log.i(TAG,"rowId in doReminderWork" + rowId);
PendingIntent pi = PendingIntent.getActivity(this, 0, notificationIntent,PendingIntent.FLAG_ONE_SHOT);
In this code , Log.i value gives correct rowId value but I dont get correct values in ReminderModificationActivity.class. onCreate() of which is having following piece of code –
mRowId = savedInstanceState != null ? savedInstanceState.getLong(TasksDBAdapter.KEY_ROWID) : null ;
registerButtonListenersAndSetDefaultText();
Log.i(TAG, "mROwId in onCreate ReminderNotification-->" + getIntent().getExtras().getLong("RowId"));
//code to check what row id have been passed
if(getIntent() != null) {
Bundle extras = getIntent().getExtras();
mRowId = extras != null ? extras.getLong("RowId") : -1;
// Do stuff with the row id here
if(mRowId != -1){
//code if RowId valid
}
}
Log.i(TAG, "mROwId in onCreate ReminderNotification again-->" + mRowId);
in this code Log.i returns value 0 even if I have sent value 4 from my notification code. please tel me where I am making a mistake. Let me know if any other details are required.
Thanks,
Ray
Check the key you’re using to get the data out. When you set it, you use a constant variable, but when you get it you use a hard coded string. It’s easy to mess up doing that.