I have a service that is set to start in a separate process:
<service android:name=".services.UploadService"
android:process=":UploadServiceProcess" />
And I can successfully bind to it using bindService(). My issue occurs when I try to send a message by calling Messenger.send():
service.send(Message.obtain(null, UploadService.MESSAGE_UPLOAD_REQUEST, uploadRequest));
where uploadRequest is a custom object that implements Parcelable
public class UploadRequest implements Parcelable {
public File file;
public boolean deleteOnUpload;
public UploadRequest(File file, boolean deleteOnUpload) {
this.file = file;
this.deleteOnUpload = deleteOnUpload;
}
private UploadRequest(Parcel in) {
this.file = new File(in.readString());
}
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.file.getPath());
}
public static final Parcelable.Creator<UploadRequest> CREATOR = new Parcelable.Creator<UploadRequest>() {
public UploadRequest createFromParcel(Parcel in) {
return new UploadRequest(in);
}
public UploadRequest[] newArray(int size) {
return new UploadRequest[size];
}
};
}
I set a breakpoint in my services handleMessage, but my app never gets to the breakpoint. However, if instead of using my custom UploadRequest object I send null, I get to the handleMessage breakpoint like I'd expect, but obviously I can't do anything at that point. I've verified file.getPath() when calling writeToParcel returns a non null String. This leads me to believe that something is off in my UploadRequest class, but from googling I can't see anything wrong with my class. Any ideas?
The documentation of Message member obj says:
My guess is you are seeing an issue because you are creating your own parcelable which is not allowed when crossing the process boundary. Instead, you’ll have to package your object into a bundle. This also means your object will need to implement Serializable but will not need to be Parcelable.