从Java代码使用C#库和Mono for Android? [英] Using C# library with Mono for Android from Java code?

查看:137
本文介绍了从Java代码使用C#库和Mono for Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能从Java代码使用带有Mono for Android的C#库吗?
可以使用mtouch命令中的--xcode标志从Objective-C到C#(MonoTouch)。但Mono for Android还有一个等价物吗?

There is a possibility to use C# library with Mono for Android from Java code? It's possible to do it from Objective-C to C# (MonoTouch) with the "--xcode" flag in the mtouch command. But there is an equivalent in Mono for Android?

并且有理由这样做吗?

谢谢!

Gwennin

推荐答案


[是否可以从Java代码中使用带有Mono for Android的C#库?

[Is it possible to] use C# library with Mono for Android from Java code?

是的。每个 Java.Lang.Object 子类都有一个 Android Callable Wrapper 在构建时生成。 Android Callable Wrapper用于允许Java代码调用托管代码(例如,当您覆盖 Activity.OnCreate() Android实际上可以调用托管覆盖。

Yes. Every Java.Lang.Object subclass has an Android Callable Wrapper generated at build time. The Android Callable Wrapper is present to allow Java code to call into managed code (e.g. so that when you override Activity.OnCreate() Android can actually invoke the managed override.

但是,有一些限制;特别是,Android Callable Wrapper中声明的唯一方法是来自已实现接口的重写方法和方法。这使Java变得复杂 - > C#场景。

However, there are a few limitations; in particular, the only methods that are declared in the Android Callable Wrapper are overridden methods and methods coming from implemented interfaces. This complicates the Java->C# scenario.


[有没有理由这样做?

[Is there] a reason to do it?

是。在许多情况下,您目前无法使用C#,例如使用 android.jar (例如 Maps API )。( Android.Runtime.JNIEnv ,但这不适用于子类化方案。)因此,最简单的方法是使用Java API是用Java编写一些代码,然后通过各种机制集成Java和托管代码,包括单独的活动(使用Activity.startActivity()从Java启动托管活动), JNIEnv ,服务等

Yes. There are a number of circumstances in which you currently can't use C#, e.g. using types that are outside of android.jar (e.g. the Maps API). (There is Android.Runtime.JNIEnv, but that doesn't work with subclassing scenarios.) As such, the easiest way to make use of the Java APIs is to write some of the code in Java, then integrate the Java and managed code via a variety of mechanisms, including separate activities (using Activity.startActivity() to launch a managed activity from Java), JNIEnv, services, etc.

这篇关于从Java代码使用C#库和Mono for Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆