Time for action – determining JNI method signatures
Let's define a Java interface that native C/C++ code will call back through JNI:
- 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); }
- 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 beStoreActivity
Public class Store implements StoreListener { private StoreListener mListener; public Store(StoreListener pListener) { mListener = pListener; } ...
Finally, implement the
StoreListener
interface and its corresponding methods, which simply forwards calls to the delegate:... public void onSuccess(int...
- Declare a member delegate