Adding the linked issue on tracker: https://code.google.com/p/android/issues/detail?id=216581&thanks=216581&ts=1468962325
So I installed the DP5 Android 7.0 release onto my Nexus 5X today. I've been working on an app that schedules local notifications at specific times using Android's AlarmManager class. Up until this release, the code has been working great on devices running KitKat, Lollipop, and Marshmallow.
Below is how I'm scheduling the alarms:
Intent intent = new Intent(context, AlarmManagerUtil.class);
intent.setAction(AlarmManagerUtil.SET_NOTIFICATION_INTENT);
intent.putExtra(AlarmManagerUtil.REMINDER_EXTRA, Parcels.wrap(reminders));
intent.putExtra("time", when.getMillis());
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
if (alarmManager != null) {
if (Build.VERSION.SDK_INT >= 23) {
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, when.getMillis(), pendingIntent);
} else if (Build.VERSION.SDK_INT >= 19) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, when.getMillis(), pendingIntent);
} else {
alarmManager.set(AlarmManager.RTC_WAKEUP, when.getMillis(), pendingIntent);
}
My AlarmManagerUtil @onReceive of the "SET_NOTIFICATION_INTENT" looks like this:
public void fireNotification(Context context, Intent intent) {
List<Reminder> reminderToFire = Parcels.unwrap(intent.getParcelableExtra(REMINDER_EXTRA));
long timeToFire = intent.getLongExtra("time", 0L); //.... }
What's strange is the "reminderToFire" is null here only on Android N devices but the timeToFire is correct.
I'm thinking its something to do with the Parceler Library? I'm compiling using Java 1.8 and targeting Android API 24.
I've definitely looked around the net for an answer to this, but my case is a bit unique since the code 100% works on all prior versions of Android (everything below N preview)...so I am following the below answers as much as I can:
How can I correctly pass unique extras to a pending intent?
Anybody else have this issue?
Parcels.wrap(reminders)
is returningnull
? Have you looked to see ifintent.getParcelableExtra(REMINDER_EXTRA)
is returningnull
, before you pass that value toParcels.unwrap()
? Have you tried stuffing some otherParcelable
into theIntent
to see if it survives the trip (e.g., aPoint
)? – HypnoIntent
being passed into thePendingIntent
argument above is being loaded with themExtras
object withmMap
containing two objects, theLong timeToFire
and the Parceled reminder object. Upon unwrap in theAlarmManager onReceive
, the Long is valid but thereminder
object is null. I'll try to Parcel some other object like aPoint
and see how it goes.Reminder
is correctly configured with@Parcel
– Caineintent.getParcelableExtra(REMINDER_EXTRA)
null
? That would indicate the value is getting lost. Ifintent.getParcelableExtra(REMINDER_EXTRA)
is notnull
, butParcels.unwrap(intent.getParcelableExtra(REMINDER_EXTRA))
isnull
, that suggests thatParcels
is having difficulty restoring the objects. – Hypnointent.getParcelableExtra(REMINDER_EXTRA)
correctly has the data; however, themExtras
object within the intent is missing themMap
object until it attempts to get the extras. Debugging now, it actually looks like unwrap is getting called with aParcelable input = null
and therefore returnsnull
. This is not the case with devices running prior versions of Android...I'll open an issue with theParceler
library on Github. Thank you sir. – Caineintent.getParcelableExtra(REMINDER_EXTRA)
is null and thusParcels.unwrap(null)
returnsnull
, but theintent.getAction()
correctly displays and theintent.getLong()
is correct as well. Sorry. You're correct. The issue seems to lie between theIntent
getting set and theBroadcastReceiver onReceive
, even thoughParcels.wrap(reminder)
successfully Parcels the object for the Intent. – Caine