In case anyone else finds this on a Google search: Most Java objects are cleaned up through garbage collection, but some need to be explicitly told to dispose of themselves when they are no longer needed. The usual example is a file handle; you need to tell Java to close that handle when you are done with it. ParcelableFileDescriptor is merely a parcelable wrapper around a file handle, so it has this same need.
Now consider this implementation of an AIDL interface: public ParcelableFileDescriptor doSomething(ParcelableFileDescriptor withFile) { someOtherRemoteAidlInterface.help(withFile); return withFile; } The question is, when do you close this ParcelableFileDescriptor? When this function returns, it still hasn't been sent back to the caller yet. However we are certainly done with it and we want to ensure it's closed. Luckily, the AIDL compiler uses PARCELABLE_WRITE_RETURN_VALUE and when the ParcelableFileDescriptor sees this flag, it automatically closes itself. So we don't have to do anything. Any ParcelableFileDescriptor that isn't being returned has to be closed explicitly: public ParcelableFileDescriptor doSomething(ParcelableFileDescriptor withFile) { someOtherRemoteAidlInterface.help(withFile); withFile.close(); return ParcelableFileDescriptor.open(new File("result file"), MODE_READ_ONLY); } ...And that's all there is to it. ParcelableFileDescriptor uses the flag to close itself. The internal framework class InputChannel uses the flag for the same reason. I don't believe there are any other parcelable objects that care whether or not PARCELABLE_WRITE_RETURN_VALUE has been set. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.