1 year ago
#308827

htafoya
Why do Activity intents may need setExtrasClassLoader but there is nothing similar for Fragment arguments?
I am having a problem with error: Class not found when unmarshalling: com.package.MyParcelableClass
(which somehow only presents on release build)
I read about using setExtrasClassLoader to make it clear that the parcelable extra should be parsed with that class.
Intent(from, MyActivity::class.java)
.apply {
setExtrasClassLoader(MyParcelableClass::class.java.classLoader)
putExtra("SOME_PARAM", param)
}
or:
@onCreate
setExtrasClassLoader(MyParcelableClass::class.java.classLoader)
val myParam: MyParcelableClass? = intent.getParcelableExtra("SOME PARAM")
That activity creates a fragment to which the same parcelable is sent
fun newInstance(param: MyParcelableClass): MyFragment {
return MyFragment().apply {
arguments = Bundle().apply {
putParcelable("SOME_PARAM", param)
}
}
}
but there is nothing similar to tell the parcelable which class to use. Why is the design different? Specially because my app is only failing when the fragment is added, the activity seems to be doing fine without specifying the class loader.
I also read that using the same intent param for both activity intent and fragment argument may cause issue, but I see no logic in that, it has never happened for me before.
android
android-fragments
android-intent
unmarshalling
parcelable
0 Answers
Your Answer