O'Reilly logo

Android NDK Beginner's Guide by Sylvain Ratabouil

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4. Calling Java Back from Native Code

To reach its full potential, JNI allows calling Java code from C/C++. This is often referred to as a callback since native code is itself invoked from Java. Such calls are performed through a reflective API, which allows doing almost anything that can be done directly in Java. Another important matter to consider with JNI is threading. Native code can be run on a Java thread, managed by the Dalvik VM, and also from a native thread created with standard POSIX primitives. Obviously, a native thread cannot call JNI code unless it is turned into a managed thread! Programming with JNI necessitates knowledge of all these subtleties. This chapter will guide you through the main ones.

Since version R5, the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required