Skip to Main Content
Android NDK Beginner`s Guide - Second Edition
book

Android NDK Beginner`s Guide - Second Edition

by Sylvain Ratabouil
April 2015
Beginner to intermediate content levelBeginner to intermediate
494 pages
10h 26m
English
Packt Publishing
Content preview from Android NDK Beginner`s Guide - Second Edition

Time for action – calling back Java from native code

Let's continue our Store by calling back the interface we defined from native code:

  1. In com_packtpub_store_Store.cpp, declare method descriptors with type jmethodID for each callback, which is going to be cached:
    ...
    static Store gStore;
    
    static jclass StringClass;
    static jclass ColorClass;
    
    static jmethodID MethodOnSuccessInt;
    static jmethodID MethodOnSuccessString;
    static jmethodID MethodOnSuccessColor;
    ...
  2. Then, cache all the callback descriptors in JNI_OnLoad(). This can be done in two main steps:

    Getting a Class descriptor with the JNI method FindClass(). One can find a class descriptor, thanks to its absolute package path, here: com./packtpub/store/Store.

    Retrieving a method descriptor from the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pro Android C++ with the NDK

Pro Android C++ with the NDK

Onur Cinar
Learning Embedded Android N Programming

Learning Embedded Android N Programming

Ivan Morgillo, Stefano Viola

Publisher Resources

ISBN: 9781783989645Supplemental Content