BadParcelableException: ClassNotFoundException when unmarshalling

后端 未结 1 651
一整个雨季
一整个雨季 2020-12-14 05:06

I\'m pretty new to Serializable and Parcelable. I\'m having a hard time passing an instance of this object from an application to a remote service:

public cl         


        
相关标签:
1条回答
  • 2020-12-14 05:49

    In this method, you never write the Bundle to the Parcel:

    public void writeToParcel(Parcel out, int flags) {
    
        out.writeInt(idEvent);
        out.writeInt(priority);
        out.writeInt(idSource);
        out.writeInt(idDestination);
        out.writeInt(action);
    
        Bundle mapBundle = new Bundle();
        mapBundle.putSerializable(MAP_KEY, (Serializable) data);
       // You need to actually write the Bundle to the Parcel here...
    }
    

    EDIT Added additional solution to the ClassLoader problem:

    Set the classloader in handleMessage() in your remote service like this:

    Bundle bundle = msg.getData();
    bundle.setClassLoader(Event.class.getClassLoader());
    Event event = (Event) bundle.get(Event.BUNDLE_KEY);
    
    0 讨论(0)
提交回复
热议问题