0

I am trying to pass this custom list object to the broadcast receiver.

For that i am passing it like this:

Inside activity:

intent.putParcelableArrayListExtra(PARCEL_LIST_GEO, parcelItems.toArrayList())

Inside broadcastReceiver:

val parcelList = intent.getParcelableArrayListExtra<ParcelItem>(PARCEL_LIST_GEO)

My problem is that when i try to receive it, it returns null.

When i use JSON on the list on the other hand, everything works, so string works. I am kinda suspecting something going wrong in the parcelable-part, but when i tested parcelable from activity to activity everything works. So the problem is just from the activity to the broadcast receiver. Is there some size limit? Or anything different with passing the object to a broadcast receiver? i dont know what i am missing...

The Dreams Wind
  • 8,416
  • 2
  • 19
  • 49
Meyben
  • 451
  • 3
  • 15

1 Answers1

0

Recently there have been a lot of problems using custom objects in Intent extras. You can try this and see if it helps. Otherwise, you will have to convert your custom object to a String and then convert it back on the receiving end. Use this before you try to read ANY extras from the Intent:

intent.setExtrasClassLoader(ParcelItem.class.getClassLoader());
David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • 1
    Sorry for late response. The setExtras didnt work sadly, but yess converting to string works :) Thank you! – Meyben Aug 14 '22 at 20:28
  • Maybe accept my answer or create your own answer and accept that, just to remove this question from the list of unanswered questions? – David Wasser Aug 15 '22 at 11:09