0

I'm trying to create an Intent with ArrayList<Byte> as extra.

So I have 3 options:

  1. putParceableArrayList(key: String?, value: ArrayList<out Parceable!>?)
  2. putByteArray(key: String?, value: ByteArray?)
  3. putSerializable(key: String?, value: Serializable?)

I would prefer to not to use the 3rd option because Parceable objects are faster than Serializable ones (Android: Difference between Parcelable and Serializable?).

Discarding this option, I want to use the first option because I need this object as an ArrayList and not as a native array bytes[] (ByteArray on Kotlin).

The problem is that Byte object is native, so it does not implements Parceable. So that, I can't use the first option because it requires ArrayList<out Parceable>.

The best option I found is to transform the ArrayList to ByteArray and transform it back to an ArrayList when I unpack the extras like so:

intent.extras?.putByteArray(event, response.toByteArray())

[...]

var list = Arrays.asList(intent.extras?.getByteArray(event))

Which is the best option? Thank you!

Nicola Gallazzi
  • 7,897
  • 6
  • 45
  • 64

1 Answers1

0

You could give a try to Parceler library, it makes your life simpler and you'll get rid of all the Parcelable interface boilerplate code

Nicola Gallazzi
  • 7,897
  • 6
  • 45
  • 64