上篇文章我们安装了NDK系统,在NDK系统文件中包含samples文件夹,打开该文件夹,我们发现里面有大量的案例项目,这里我们通过Eclipse导入一个名为hello-jni的项目
导入成功后,我们可以看到项目目录如下:
然后,我们逐个学习案例源码
1.声明Native方法
- 打开com.example.hellojni目录下的HelloJni.java
package com.example.hellojni;
import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;
public class HelloJni extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
/* Create a TextView and set its content.
* the text is retrieved by calling a native
* function.
*/
TextView tv = new TextView(this);
tv.setText( stringFromJNI() );
setContentView(tv);
}
/* A native method that is