Time for action – determining JNI method signatures

Let's define a Java interface that native C/C++ code will call back through JNI:

  1. Create a StoreListener.java, which contains an interface defining a few callbacks, one for integers, one for strings, and one for colors, as follows:
    package com.packtpub.store;
    
    public interface StoreListener {
        void onSuccess(int pValue);
    
        void onSuccess(String pValue);
    
        void onSuccess(Color pValue);
    }
  2. Open Store.java and make a few changes.
    • Declare a member delegate StoreListener, to which success callbacks are sent
    • Change the Store constructor to inject the delegate listener, which is going to be StoreActivity
      Public class Store implements StoreListener {
          private StoreListener mListener; public Store(StoreListener pListener) ...

Get Android NDK Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.