“BadParcelableException: ClassNotFoundException when unmarshalling ” while using Parcel.read method that has a ClassLoader as argument

前端 未结 4 1702
我寻月下人不归
我寻月下人不归 2020-12-02 10:16

Given a custom class org.example.app.MyClass implements Parcelable, I want to write a List to a Parcel. I did the marshalling with

4条回答
  •  萌比男神i
    2020-12-02 11:05

    I have faced the same problem and instead of parcleable I used bundle

    intent.setExtrasClassLoader(getClassLoader());
    /* Send optional extras */
    Bundle bundle = new Bundle();
    bundle.putParcelable("object", mObject);
    bundle.putString("stringVal", stringVal);
    
    intent.putExtra("bundle",bundle);
    

    And in my intent class I used this to retrieve the value:

    Bundle oldBundle = intent.getBundleExtra("bundle");
    ResultReceiver receiver = oldBundle.getParcelable("object");
    String stringVal = oldBundle.getString("stringVal");
    intent.setExtrasClassLoader(getClassLoader());
    

    Hope it will be helpful for some.

提交回复
热议问题