別のプロセスで開始するように設定されたサービスがあります。
<service android:name=".services.UploadService"
android:process=":UploadServiceProcess" />
そして、bindService() を使用して正常にバインドできます。Messenger.send() を呼び出してメッセージを送信しようとすると、問題が発生します。
service.send(Message.obtain(null, UploadService.MESSAGE_UPLOAD_REQUEST, uploadRequest));
ここで、uploadRequest は 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]; } };
}
サービスの handleMessage にブレークポイントを設定しましたが、アプリがブレークポイントに到達しません。ただし、カスタム UploadRequest オブジェクトを使用する代わりに null を送信すると、期待どおりに handleMessage ブレークポイントに到達しますが、明らかにその時点では何もできません。writeToParcel を呼び出すと null 以外の文字列が返される場合に file.getPath() を確認しました。これにより、UploadRequest クラスで何かがおかしいと思われますが、グーグルで調べてもクラスに問題はありません。何か案は?