Many people should be impressed with the JNI (NDK), the Android NDK has a relatively good chance of exposure, this example on the Android platform, for example, the PC side of the simple windows as an example, the code finished with VS or gcc compiled into DLL files, Thrown into the system system32, is the environment variable configuration folder under, Linux may also be similar to this meaning, the rest of the code is like Android, to load the dynamic link library.
Here do not repeat, directly into the Android platform of the NDK development, here is the main point, the Java layer How to persist C C + + objects, the scenario can be, suppose you create an object in the C/S layer (structure), you want to continue to use the next time what to do, of course, to save it, How to save it, it is necessary to consider how to persist it, turn over Java or Android many of the source code is always placed on a long object play.
For example:
Yes, there seems to be nothing special a field, in fact, is the bottom of a C + + object, than the Mnativebitmap in the chip is actually a bitmap object in C/s, need it will be in the bottom of the transformation, it may be said that we do not understand here I use code to illustrate the next.
First, create a new native class:
Then use the tool to generate the header file declaration, this self-Baidu solution, here do not repeat, now to show the most important C + + code, here I use C + + encoding.
First I created a class, C inside is the struct, with C + + syntax to create the object is to use new, that C is malloc, this is not much to do, this is a comparison of the main two-segment code
(Jlong) person; and (person *) Nativeid;
Each of these two pieces of code is a transformation, one is converted to Jlong (that is, the long type in Java), from the Java layer calls the C + + layer and then return Jlong to the Java layer of a long object to persist. When using, the long is uploaded to C + + Layer is strongly turned into person *, so you can continue to use it. This is a very simple code, but it is really practical ~
Source code Address: http://download.csdn.net/detail/jue_dui_zhen_li/9570118
Originating From: http://blog.csdn.net/jue_dui_zhen_li/article/details/51852438
(GO) Java layer invoke JNI (NDK) Persistent c C + + object