Android java pass int type array to C

Source: Internet
Author: User

Then the previous article "Android Java pass int type data to C" "Android Java Pass string type data to C", continue to practice

Implement public native int[] Arrelementsincrease (int[] intarray);

Project layout

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"Tools:context=". Mainactivity " >    <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:onclick= "click"Android:text= "Pass int type parameter" />    <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:onclick= "Passstring"Android:text= "Pass String type parameter" />    <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:onclick= "Passintarray"Android:text= "Pass int type array" /></LinearLayout>

Implementing the Arrelementsincrease function

/** Class:com_wuyudong_javapassdata_jni * method:arrelementsincrease * Signature: ([i) [I*/jniexport jintarray jnicall java_com_wuyudong_javapassdata_jni_arrelementsincrease (JNIEnv*env, Jobject clazz, Jintarray Jarray) {Jsize len= (*env)getarraylength (env, Jarray); //Jboolean iscopy;      int* Arraypointer = (*env)getintarrayelements (env, Jarray, NULL); inti;  for(i =0; i < Len; i++){          * (Arraypointer + i) + =Ten; }      returnJarray;}

Add the following code to the Mainactivity.java:

     Public void Passintarray (View v) {        intnewint[] {1, 2, 3, 4, 5 };         int [] NewArray = jni.arrelementsincrease (array);          for (int  i:newarray) {            log.d ("test", I + "");        }    }

Android java pass int type array to C

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.