0

I have this custom class which I made parcelable and used until now. I was able to put that class in an intent as an extra and use alarm manager to set when it should come back on my onReceive class. This worked for api level 23.

I have tried running my code on a phone that had Android 7.0(api level 24) and the extras of the intent would be null. I read that this is no longer possible in android api level 24+, and that apart from raw types no custom parcelable class can be added as an extra. My question is how do I get around these problems? I need a lot of the properties from the parcelable class to be transferred and adding different types of data one by one seems unreasonable to me.

Nick
  • 825
  • 1
  • 8
  • 20

1 Answers1

1

I read that this is no longer possible in android api level 24+, and that apart from raw types no custom parcelable class can be added as an extra

Correct. Passing a custom Parcelable outside of your process is risky, as if another process tries to read it in, it does not have your Parcelable class, and therefore it crashes.

My question is how do I get around these problems?

One solution is to convert your Parcelable into a byte[] yourself, putting the byte[] into the extra. Then, reverse the process when you retrieve it. Other processes will not need your custom class. This Stack Overflow answer outlines the technique; this sample app demonstrates it.

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for the links, I will try that now ! – Nick Feb 11 '17 at 14:47
  • First link's answer for some reason didn't work(maybe my wrong implementation) but second link actually helped me a lot. Thanks ! – Nick Feb 11 '17 at 15:56