Skip to content

Instantly share code, notes, and snippets.

@filipproch
Created June 17, 2016 06:04
Show Gist options
  • Save filipproch/da6edb3268a215ecf73007039217f02c to your computer and use it in GitHub Desktop.
Save filipproch/da6edb3268a215ecf73007039217f02c to your computer and use it in GitHub Desktop.
test creating objects in c++
//
// Created by Filip Prochazka (@filipproch)
//
#include <jni.h>
#ifdef __cplusplus
extern "C"
{
#endif
JNIEXPORT void JNICALL Java_cz_filipproch_testjniobjects_MainActivity_test( JNIEnv* env,
jobject thiz ) {
jclass clazz = env->FindClass("cz/filipproch/testjniobjects/MainActivity");
jmethodID callbackMethodId = env->GetMethodID(clazz, "testCallback", "(Lcz/filipproch/testjniobjects/Data;)V");
jclass dataClazz = env->FindClass("cz/filipproch/testjniobjects/Data");
jmethodID setInt = env->GetMethodID(dataClazz, "setInt", "(I)V");
jmethodID constructor = env->GetMethodID(dataClazz, "<init>", "()V");
jobject dataObject = env->NewObject(dataClazz, constructor);
env->CallVoidMethod(dataObject, setInt, 55);
env->CallVoidMethod(thiz, callbackMethodId, dataObject);
}
#ifdef __cplusplus
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment