android 应用的 Kivy 和 Java 之间的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18553849/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 09:00:00  来源:igfitidea点击:

Difference between Kivy and Java for android apps

javaandroidpythonkivy

提问by Guilherme David da Costa

I'm a python developer with little experience creating android apps in java and want to create an app that will access my university web portal, retrieve some data and show on a view.

我是一名 Python 开发人员,几乎没有在 Java 中创建 Android 应用程序的经验,我想创建一个应用程序来访问我的大学门户网站、检索一些数据并在视图中显示。

So, after researching Kivy, I have a few questions:

所以,在研究了 Kivy 之后,我有几个问题:

1)Which one is easier and faster to develop android apps?

1)哪一个更容易和更快地开发Android应用程序?

2)Does Kivy have any android feature limitations?

2)Kivy 是否有任何安卓功能限制?

3)And finally, would an android app developed using kivy run as fast as one developed using java?

3)最后,使用 kivy 开发的 android 应用程序运行速度是否与使用 java 开发的应用程序一样快?

采纳答案by inclement

This is a rather subjective question.

这是一个比较主观的问题。

1) Which one its easier and faster to develop android apps?

1) 哪一个更容易、更快速地开发 Android 应用程序?

I think there's a strong argument for kivy, but this doesn't have an objective answer.

我认为 kivy 有一个强有力的论据,但这没有客观的答案。

2) Does Kivy has limitations to access certain parts of android (like not fully integrated with its api)?

2) Kivy 是否有访问 android 某些部分的限制(例如未与其 api 完全集成)?

The kivy project includes pyjnius, a tool for accessing java classes through python, and in principle I think this should give arbitrary (edit: on reflection, not arbitrary, but probably not limited in immediately important ways) access to the java apis.

kivy 项目包括 pyjnius,一个通过 python 访问 java 类的工具,原则上我认为这应该提供对 java apis 的任意(编辑:反射,不是任意的,但可能不限于直接重要的方式)访问。

In practice, prebuilt python wrappers are a work in progress, though rapidly improving. The android python library already gives easy access to many things (including but not limited to intents, vibration, accelerometer etc.). Even where there isn't already a python wrapper, it can be very easy to do the necessary work.

在实践中,预构建的 Python 包装器正在进行中,但正在迅速改进。android python 库已经可以轻松访问许多东西(包括但不限于意图、振动、加速度计等)。即使还没有 Python 包装器,也可以很容易地完成必要的工作。

Edit: There has recently been great work on Kivy's plyerproject, intended to provide a transparent api to platform specific tools so that you can call it once and get the same behaviour on different systems without knowing about the details. It includes useful support for parts of the android api.

编辑:最近在 Kivy 的plyer项目上做了大量工作,旨在为特定于平台的工具提供透明的 api,以便您可以调用它一次并在不同系统上获得相同的行为,而无需了解细节。它包括对 android api 部分的有用支持。

3) And finally, an android app developed using kivy would run as fast as one developed using java?

3) 最后,使用 kivy 开发的 android 应用程序运行速度与使用 java 开发的应用程序一样快?

Ultimately the answer is probably no, but the difference is highly unlikely to be important unless you're doing something strongly cpu limited. The task you suggest would not be limited in that way.

最终答案可能是否定的,但除非您正在做一些 CPU 非常受限的事情,否则差异不太可能很重要。您建议的任务不会以这种方式受到限制。

回答by Tshirtman

To complete inclement's answer, pyjnius indeed allows to access a lot of the android api. But it's not perfect, calling existing classes is not always enough, and an android programmer often need to create code that will be called by android to manage events, there are two ways to do that, both used by the android api.

为了完成 inclement 的回答,pyjnius 确实允许访问很多 android api。但这并不完美,调用现有的类并不总是足够的,而且一个 android 程序员经常需要创建将由 android 调用的代码来管理事件,有两种方法可以做到这一点,都由 android api 使用。

  • The first one is interfaces: you need to create a class that implement an existing java interface, pyjnius can do that, you create a python class and declare which java interface it implements, and have a decorator to declare the methods you have to declare.
  • The second is subclassing, you need to subclass an existing java class and override some methods, and we don't have a way to do that with pyjnius yet, so for these ones, you'd have to create a java class and use it in your program (fortunately you can mix that with kivy/pyjnius, it's just can't be 100% python in that scenario).
  • 第一个是接口:您需要创建一个实现现有 java 接口的类,pyjnius 可以做到这一点,您创建一个 python 类并声明它实现了哪个 java 接口,并有一个装饰器来声明您必须声明的方法。
  • 第二个是子类化,你需要子类化一个现有的java类并覆盖一些方法,我们还没有办法用pyjnius来做到这一点,所以对于这些,你必须创建一个java类并使用它在您的程序中(幸运的是,您可以将它与 kivy/pyjnius 混合使用,在那种情况下它不能是 100% 的 python)。

So it can be worth a look to the api beforehand, to see if the parts of the android api you have to access requires that.

因此,值得事先查看 api,看看您必须访问的 android api 部分是否需要。