1 package com.example.jniexample; 2 3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.widget.TextView; 6 7 public class JNIExample extends Activity { 8 /** Called when the activity is first created. */ 9 @Override 10 public void onCreate(Bundle savedInstanceState) { 11 super.onCreate(savedInstanceState); 12 TextView tv = new TextView(this); 13 int sum = Native.add(2, 3); 14 tv.setText("Native Code test: 2 + 3 = " + Integer.toString(sum)); 15 setContentView(tv); 16 } 17 } 18 19 class Native { 20 static { 21 System.loadLibrary("native"); 22 } 23 24 static native int add(int a, int b); 25 } 26