问题
Not being patient enough for the Mono for Android book I started going through the Android programming constructs and translate them to the Mono infrastructure. Seems like most the time the good folks at Xamarin and I think along similar lines so progress has been relatively pain free but on the AIDL issue I'm stuck. Was AIDL implemented? If so, how can I use it? If not, what is the recommended way to use IPC?
回答1:
AIDL is, lamentably, something that isn't readily supported at this time. It is only supported via Java Interop Support; that is, you'd need to:
- Write your
.aidlfiles. - Compile the
.aidlfiles into.javafiles (possibly as a pre-build step?). - Include the generated
.javafiles into your build by adding them to the project and setting their build action to AndroidJavaSource.
Of course, for parcels you'll need to implement them...in Java, and for services you'll likewise need to write some Java code.
The documentation on Java Native Interop Support may be useful as well.
In all, not very elegant. Not difficult, but not elegant either.
Consequently, the recommended way to do IPC is to use Intents, BroadcastReceivers, and ContentProviders (depending on the needs of your IPC), and avoiding the use of parcels; use Strings and other builtin types instead.
回答2:
AIDLs are finally supported. To use them add aidl files into your project and set Build Action to AndroidInterfaceDefinition. Xamarin.Android will generate cs files, that are compiled together with your source code, so you can use aidl interfaces in your c# code. VS2012 still marks them as unknown/errors in code, but in the end, code is compiled and working.
来源:https://stackoverflow.com/questions/7872505/using-aidl-with-mono-for-android