I've been breaking my head with this for a few days so I hope someone can point out what I'm doing wrong. I'm creating an intent with 5 string extras and setting it to a PendingIntent to use with AlarmManager. However when the alarm triggers and I proceed with handling the intent inside onHandleIntent of my service class, there are only 3 extras in the Intent. Some code & screenshots below.
Intent creation:
Intent notificationIntent = new Intent("android.media.action.DISPLAY_NOTIFICATION");
;
notificationIntent.addCategory("android.intent.category.DEFAULT");
notificationIntent.putExtra("key1", "val5");
notificationIntent.putExtra("key2", "val4");
notificationIntent.putExtra("key3", "val3");
notificationIntent.putExtra("key4", "val4");
notificationIntent.putExtra("key5", "val5");
return notificationIntent;
Pending Intent creation:
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getActivity(), Integer.parseInt(obj.uniqueId), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Inside intent service:
protected void onHandleIntent(Intent intent) {
if(intent != null) {
if (intent.getExtras() != null) {
String val1 = intent.getStringExtra("key1");
String val2 = intent.getStringExtra("key2");
String val3 = intent.getStringExtra("key3");
String val4 = intent.getStringExtra("key4");
String val5 = intent.getStringExtra("key5");
// proceed with other stuff..
}
}
}
Based on some other answer's to questions similar to mine, I've also tried:
final Intent originalIntent = (Intent)intent.getExtras().get( Intent.EXTRA_INTENT );
final String val1 = originalIntent.getStringExtra("key1");
But the originalIntent is always null. I can't figure out why only 3 of the extras are available and the other 2 aren't. They are all String values so the discrimination is beyond my understanding :(
Debugger screenshots:
When intent is created -
When intent is read in intent service class -
I also tried doing intent.setAction("",Math.random());
as suggested in some answers on SO but that resulted in the alarm not triggering at all.
Any help is greatly appreciated.
You've added your "extras" to a broadcast Intent
and then you claim that in your Service
only 3 of the 5 show up. How about looking at the code that extracts the "extras" from the broadcast Intent
in onReceive()
and copies them to the Intent
you use to call startService()
. I think you'll find your problem is right there :-)