Book Image

Android NDK: Beginner's Guide

By : Sylvain Ratabouil
Book Image

Android NDK: Beginner's Guide

By: Sylvain Ratabouil

Overview of this book

Table of Contents (18 chapters)
Android NDK Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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) {
              mListener = pListener;
          }
          ...

      Finally, implement the StoreListener interface and its corresponding methods, which simply forwards calls to the delegate:

          ...
          public void onSuccess(int pValue) {
      ...