将AIDL与Mono for Android结合使用 [英] Using AIDL with Mono for Android
问题描述
对Android版《 Mono》没有足够的耐心,我开始研究Android编程结构并将其转换为Mono基础结构.似乎大多数时候,Xamarin的好伙伴和我都遵循类似的思路,因此进展相对较轻松,但是在AIDL问题上,我遇到了麻烦. AIDL是否已实施?如果可以,该如何使用?如果没有,推荐使用IPC的方法是什么?
可悲的是,AIDL目前尚不支持.仅通过 Java Interop支持支持.也就是说,您需要:
- 写入您的
.aidl
文件. - 将
.aidl
文件编译为.java
文件(可能是预构建步骤?).
通过将生成的
.java
文件添加到项目中并将其生成操作设置为 AndroidJavaSource ,将它们添加到生成中.
当然,对于parcel
,您将需要在Java中实现它们;对于服务,您同样需要编写一些Java代码.
Java Native Interop支持上的文档也可能有用./p>
总的来说,不是很优雅.不难,但也不优雅.
因此,推荐的IPC方式是使用Intent,BroadcastReceivers和ContentProvider(取决于IPC的需求),并避免使用包裹.改用Strings和其他内置类型.
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?
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
.aidl
files. - Compile the
.aidl
files into.java
files (possibly as a pre-build step?). - Include the generated
.java
files into your build by adding them to the project and setting their build action to AndroidJavaSource.
Of course, for parcel
s 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.
这篇关于将AIDL与Mono for Android结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!