https://kotlinlang.org logo
Title
a

AndreiBogdan

05/02/2023, 2:28 PM
Hello. I have a very simple class which stores 2 Strings and manipulates them in certain ways and it was previously Parcelable. I'd like to move that class to the shared module but i am uncertain how to then pass the instance of that object via Bundles / Intents on Android as i currently am. What is the best practice in that regard ?
a

ayodele

05/02/2023, 2:32 PM
Between activities or composables??
a

AndreiBogdan

05/02/2023, 2:32 PM
activities
a

ayodele

05/02/2023, 2:34 PM
You should pass the data instead into the activities then retrieve them for your class to use
Or must you pass the entire class??
a

AndreiBogdan

05/02/2023, 2:36 PM
i want to pass the entire instance of that class. the code's already implemented, i was hoping not to change it. for this specific case, with the 2 strings, it would be simple, yes, but for more complex classes containing multiple data types ... i think there might be some sort of mechanism to do it ...
p

psh

05/02/2023, 2:37 PM
You can use the kotlin-parcelize plugin, with an expect/actual (and typealias) to isolate the annotation over on Android
a

AndreiBogdan

05/02/2023, 2:37 PM
hmm, i will look into what you said. thank you ! and i'm guessing this does not affect iOS in any way
a

ayodele

05/02/2023, 2:37 PM
What about injecting it then
p

psh

05/02/2023, 2:38 PM
Also, look at the
OptionalExpectation
annotation - it will allow you to skip any boiler-plate blank iOS implementation
a

AndreiBogdan

05/02/2023, 2:38 PM
Thank you very much !