Android cannot pass intent extras though AlarmManager

前端 未结 2 784
轮回少年
轮回少年 2020-11-27 15:49

I am trying to put an extra message in my intent to pass to AlarmManager to be triggered at a later time. My onReceive triggers correctly but extras.getString() returns null

2条回答
  •  时光取名叫无心
    2020-11-27 16:24

    I have some precisions that could help others, to be associated with the solution from Someone Somewhere. If you pass custom Parcelable objects as an extra, the operating system may not be able to process them, so an internal exception occurs and your extras are lost.

    With Android N, even with PendingIntent.FLAG_UPDATE_CURRENT I cannot retrieve my custom Pacelable extras.

    So I had to use system known Parcelable (like ParcelUuid) to reference some objects in a custom database instead of providing my whole Parcelable object.

    Another solution is to convert Parcelable to a byte array that is correctly recognized by the system: How to marshall and unmarshall a Parcelable to a byte array with help of Parcel?

提交回复
热议问题