I have Activity A which starts Activity B with following code:
Intent intent = new Intent(this, B.class);
intent.putExtra("foo", new MySerializableObject());
startActivity(intent);
In B "foo" is received correctly and then I create PendingIntent to start itself after some time, you can think about it as some alarm clock app. Anyway the mysterious thing is that when I schedule this intent in following way:
Intent intent = new Intent(context, B.class);
intent.putExtra("bar", true);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + delayMs, pendingIntent);
Then everything is fine (after receiving this intent "bar" value is true), however if I add following line before or after "bar":
intent.putExtra("foo", new MySerializableObject());
Then when I receive this intent both "foo" and "bar" are missing. I mean false is returned from both of those lines:
getIntent().hasExtra("foo")
getIntent().hasExtra("bar")
What could be the reason of such behaviour?
EDIT: Basing on suggestion in comments I've tried:
intent.putExtra("foo", true);
intent.putExtra("bar", true);
and it worked, so I thought that maybe there is something wrong with MySerializableObject, so this is what I've tried next:
intent.putExtra("foo",
new Serializable() {
@Override
public int hashCode() { return super.hashCode(); }
});
intent.putExtra("bar", true);
But this causes exactly the same problem as I described ("foo" and "bar") are missing. Finally I've also tried replacing "foo" with "xxx" but it didn't change anything, so to me it looks like some weird Android bug.