Hi there,
I want to send my custom object which implements Parcelable from one
process(application) to an activity in another one process. But I
still get error message: BadParcelableException:
ClassNotFoundException when unmarshalling. I accepted some advices but
still not working. Here is my code:
// here is my class which implements parcelable and which i want to
send
public class Place implements Parcelable{
int ID;
String name;
boolean in;
boolean notify;
public Place(int ID , String name, boolean notify) {
this.ID = ID;
this.name = name;
in = false;
this.notify = notify;
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(ID);
dest.writeString(name);
dest.writeInt((in)? 1:0);
dest.writeInt((notify)? 1:0);
}
public static final Parcelable.Creator<Place> CREATOR = new
Creator<Place>() {
@Override
public Place[] newArray(int size) {
return new Place[size];
}
@Override
public Place createFromParcel(Parcel source) {
return new Place(source);
}
};
private Place(Parcel p) {
ID = p.readInt();
name = p.readString();
in = ((p.readInt() == 0)? false:true);
notify = ((p.readInt() == 0)? false:true);
}
}
// In the service I put the Place object into bundle and I add it as
data to message, then i send it to replyTo(Messenger of the activity)
try {
b = new Bundle();
b.putParcelable("place", allPlaces.get(0));
m = Message.obtain(null, GET_PLACE);
m.setData(b);
msg.replyTo.send(m);
} catch (RemoteException e1) {
e1.printStackTrace();
}
// Here is the handler which handles the message
b = new Bundle();
b = msg.getData();
b.setClassLoader(getClassLoader()); // somewhere i read i should reset
the class loader to the loader of the activity in different process
Place p = (Place) b.getParcelable("place");
Toast.makeText(getApplicationContext(), "name: "+p.name,
Toast.LENGTH_SHORT).show();
Can you help me pls or am I missing something? I'm going crazy, every
advice is worth.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en