Android的NativeActivity的 [英] Android NativeActivity

查看:320
本文介绍了Android的NativeActivity的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助的Andr​​oid NDK 刚刚显著扩大到包括完全在本地C编写Android应用程序的支持/ C ++ code。现在,人们可以获取使用本地code键盘和触摸屏上输入事件,并且也实现了应用程序生命周期中的C / C ++使用新的NativeActivity的类。

The Android NDK has just been significantly expanded to include support for writing android applications entirely in native C/C++ code. One can now capture input events on the keyboard and touch screen using native code, and also implement the application lifecycle in C/C++ using the new NativeActivity class.

由于所有的扩展本机功能,会是值得完全绕过Java和写在本土code Android应用程序?

Given all the expanded native capabilities, would it be worthwhile to completely bypass Java and write Android application in native code?

推荐答案

NDK的是不是本机每本身。这是在很大程度上左右了Android SDK的JNI封装。使用NativeActivity的给你处理某些应用程序生命周期事件的简便方法,并添加自己的原生code之上。 ALooper,AInputQueue等都是Java SDK的同行,一些额外的code,它是私有的,不可访问真正的应用程序的所有JNI包装。

The NDK is not native per-se. It is to a large extent a JNI wrapper around the Android SDK. Using NativeActivity gives you a convenient way of dealing with certain app-life cycle events, and add your own native code on top. ALooper, AInputQueue etc. are all JNI wrappers of the Java SDK counterparts, some with additional code that is private and unaccessible for real apps.

当谈到Android的发展,有没有这样的事情在本地C ++编写的应用程序完全是 - 你会(在每一个真正的应用程序的情况下,我能想到的)总是需要使用Android API:s,这是一个巨大的程度上纯Java。无论您使用的这些通过自己创建的NDK或包装提供的包装并没有真正改变这一点。

When it comes to Android development, there's no such thing as writing an application entirely in native C++ - you will (in every real App case that I can think of) always need to use the Android API:s, which are to a huge extent pure Java. Wether you use these through wrappers provided by the NDK or wrappers that you create yourself doesn't really change this.

因此​​,要回答你的问题:不,这不会是值得的,因为你最终会写JNI包装的SDK调用,而不是写JNI来包装自己的Java方法做同样的事情,用量少,code,简单的code和更快的code。例如,显示一个对话框,使用纯C ++,涉及到相当多的JNI调用。只需调用Java方法通过JNI,做同样的事情会给你更快code(一个JNI调用),可以说,code,它更容易维护。

So, to answer your question: No, it wouldn't be worthwhile, because you would end up writing JNI wrappers for SDK calls instead of writing JNI wrappers to your own Java methods that do the same thing, with less code, simpler code and faster code. For example, showing a dialog using "pure c++", involves quite many JNI calls. Just calling a Java method through JNI that does the same thing will give you faster code (one JNI call), and, arguably, code that is easier to maintain.

要充分了解你能做什么,你真的必须检查Android源$ C ​​$ C。先从native_app_glue.c,它可在NDK,然后继续OS实现AActivity,ALooper中,AInputQueue等谷歌code搜索,这是一个很大的帮助。 : - )

To fully understand what you can do, you really must examine the Android source code. Start with native_app_glue.c, which is available in the NDK, then continue with the OS implementation of AActivity, ALooper, AInputQueue etc. Google Code Search is a great help in this. :-)

如果它是很容易做到在Java中,并包含了许多电话,称通过JNI,做这一切,而不是写的所有额外的code与多个JNI调用做到这一点的方法。 preserve尽可能多的将现有的C ++ code原样的合理的。

If it is easy to do in Java, and includes many calls, call a method through JNI that does it all, rather than writing all the extra code to do it with multiple JNI calls. Preserve as much of your existing C++ code as is reasonable.

这篇关于Android的NativeActivity的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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