Accessing Java objects from native code

When we call a native function, the C or C++ function receives a JNIEnv pointer to a table of JNI methods used to interact with JVM Runtime. The JNIEnv pointer provides us with a set of primitives ready to find a Java class definition, set or get Java object field values, call static or member Java object functions, create Java objects, interact with Java monitors, or deal with exceptions.

Our next example will count the number of words on an EditText UI Widget on a native function and update a TextView text with count results from the native code. Therefore, we will learn how to use JNIEnv to access a member Java object field and how to call a Java object method (TextView.setText) using the JNIEnv interface. ...

Get Asynchronous Android Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.