編輯:中級開發
Java代碼:
package eagle.test;
public class EagleUI extends Activity
TextView mTextVIEw;
MainHandler mMainHandler;
static MainHandler mHandler;
//------------------------------------------------------
static System.loadLibrary("EagleZip");// 聲明所要調用的庫名稱
//------------------------------------------------------
@Override
public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);
mTextView=(TextView)findViewById(R.id.MyTextVIEw);
mMainHandler=new MainHandler();
mHandler=mMainHandler;
WorkThread tThread = new WorkThread ();
new Thread(tThread).start();
}
//------------------------------------------------------
public static void myCallbackFunc(String nMsg) Message tMsg=new Message();
Bundle tBundle=new Bundle();
tBundle.putString("CMD", nMsg);
tMsg.setData(tBundle); mHandler.sendMessage(tMsg); //------------------------------------------------------
public static native String myJni(String nParam);// 對要調用的方法做本地聲明
//------------------------------------------------------
public class zipThread implements Runnable @Override
public void run() myJni("Eagle is great");
}
}
//------------------------------------------------------
class MainHandler extends Handler public MainHandler(){}
public MainHandler(Looper L) super(L);
public void handleMessage(Message nMsg) super.handleMessage(nMsg); Bundle tBundle=nMsg.getData();
String tCmd=tBundle.getString("CMD"); EagleUI.this.mTextVIEw.setText(tCmd); }
Java代碼:
#include <jni.h>jclass gJniClass;
jmethodID gJinMethod;
//---------------------------------------------------------------
JNIEXPORT JString JNICALL
Java_eagle_test_EagleUI_myJni(JNIEnv* env, jclass cls,JString param) char tChar[256];
const char *tpParam; gJniClass = cls;
gJinMethod = 0;
gJinMethod=(*env)->GetStaticMethodID(env,gJniClass,"myCallbackFunc","(LJava/lang/String;)V");
if(gJinMethod == 0 || gJinMethod == NULL)
return (*env)->NewStringUTF(env, "-2"); strcpy(tChar,"Hello Eagle");
(*env)->CallStaticVoidMethod(env,gJniClass,gJinMethod,(*env)->NewStringUTF(env, tChar));
DisplayCallBack(env,tChar);
tpParam =(*env)->GetStringUTFChars(env,param,0);
return param;
}
//---------------------------------------------------------------
void DisplayCallBack(JNIEnv* env,char nMsg[]) char tChars[256]; strcpy(tChars,nMsg);
(*env)->CallStaticVoidMethod(env,gJniClass,gJinMethod,(*env)->NewStringUTF(env, tChars));
}
簡介: 學習了解 IBM® Rational® Rhapsody® V7.5.2 版本中的新特性與改進之處,幫助系統管理員和實時、嵌入
這幾天搞了搞AIDL,終於弄明白了在AIDL中讓Service調用Activity的方法代碼:首先建立一個ICallback.aidl文件,作為Activity中的回調
簡介: 學習如何使用混合應用程序編程模型為 WebSphere® Commerce 構建移動應用程序。本文描述混合模型,它與其他移動應用程序編程模型的
簡介: Java™ 語言是 Android 開發人員所選的工具。android 運行時使用自己的虛擬機 Dalvik,這並不是多數程序開發人員使用