Android third-party SDK Learning notes (ii)

Source: Internet
Author: User

Let's see the JNI section today.

The static system.loadlibrary ("String") in the main activity;

This is to load the library you are loading, possibly a file or a namespace, and so on.

Public native functionname (); This is a function that declares that you need to call in the JNI, only as a declaration without having to define the implementation.

Usually it's just passing some basic types, complex types I don't know how to do it, that's enough.

Most of the passes are shaped or character-shaped variables, which are the things you buy or the simple messages you pass.

Because Java and C are not directly intermodulation, it is also necessary to master the basic types of JNI, which are also simple, almost as long as the basic type before adding a "J" OK

For example Int->jint double->jdouble Boolean->jboolean

These are basic, and there are jobject. This is the parent class of all classes in JNI, similar to the Java object.

Look at the Jni file, the Java layer called the native method, in the Jni file should be the name of the definition, otherwise generated so library of the trouble

For example, the main class of my Java is the mainactivity under the Hbsi.dtd.game package.

Then the Nativite method to be implemented in your JNI will be written

Jniexport void Jnicall java_hbsi_dtd_test_mainactivity_fucntionname (jnienv *, jobject);

If you return to reshape or you want to pass parameters to

Jniexport jint jnicall java_hbsi_dtd_test_mainactivity_fucntionname (jnienv *, jobject,jint AGR);

And so on The first parameter is to pass the jnienv in, jnienv is the current thread, by calling Android::androidruntime::registernativemethods () to register the native implementation of the function pointer.

Generally in the game these things are packaged by the game engine, the bottom of the package to do a good understanding, can add a method to use is enough.

There's a lot more to learn.

Android third-party SDK Learning notes (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.