I am attempting to use the android NDK.
Is there a way to return an array (in my case an int[]) created in JNI to Java? If so, please provide a quick example of the JNI function that would do this.
-Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you’ve examined the documentation and still have questions that should be part of your initial question. In this case, the JNI function in the example creates a number of arrays. The outer array is comprised of an ‘Object’ array creating with the JNI function
NewObjectArray(). From the perspective of JNI, that’s all a two dimensional array is, an object array containing a number of other inner arrays.The following for loop creates the inner arrays which are of type int[] using the JNI function
NewIntArray(). If you just wanted to return a single dimensional array of ints, then theNewIntArray()function is what you’d use to create the return value. If you wanted to create a single dimensional array of Strings then you’d use theNewObjectArray()function but with a different parameter for the class.Since you want to return an int array, then your code is going to look something like this: