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

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

问题描述

有可能从 Java 代码中将 C# 库与 Mono for Android 一起使用吗?可以使用 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?

这样做有什么理由吗?

谢谢!

格温宁

推荐答案

[是否可以]从 Java 代码中将 C# 库与 Mono for Android 一起使用?

[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.

[是否有理由这样做?

是的.在许多情况下,您目前无法使用 C#,例如使用 android.jar 之外的类型(例如 地图 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天全站免登陆