Search code examples
androidandroid-intentbundleparcelableonactivityresult

Cannot read Parcelable from Intent in onActivityReenter


I want to return my address model as result in Intent. If I try get my address model in onAcivityResult methods all works fine, but in onActivityReenter I got this Exception:

Class not found when unmarshalling: ua.com.uklontaxi.models.UIAddress
java.lang.ClassNotFoundException: ua.com.myapp.models.UIAddress
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:324)
    at android.os.Parcel.readParcelableCreator(Parcel.java:2383)
    at android.os.Parcel.readParcelable(Parcel.java:2337)
    at android.os.Parcel.readValue(Parcel.java:2243)
    at android.os.Parcel.readArrayMapInternal(Parcel.java:2592)
    at android.os.BaseBundle.unparcel(BaseBundle.java:221)
    at android.os.Bundle.getParcelable(Bundle.java:786)

There are not such errors in another places (for example onActivityResult in the same Activity)

How to fix it?

P.S. I put my model to Bundle and then I put this bundle to Intent. I tried put address to Intent without Bundle-wrapping. It doens't help me.


Solution

  • This helps me:

    override fun onActivityReenter(resultCode: Int, data: Intent?) {
       super.onActivityReenter(resultCode, data)
    
       data?.setExtrasClassLoader(this.classLoader) // this is context!
    }