Search
 
SCRIPT & CODE EXAMPLE
 

CPP

android call custom managed method from native code

JNIEnv *env = activity->env;
jobject activity_obj = activity->clazz;

// Custom classes cannot be found directly - such a class needs to be loaded with Activity's ClassLoader.

// Get ClassLoader:
jclass activity_class = env->GetObjectClass(activity_obj);
jmethodID get_class_loader_mid = end->GetMethodID(activity_class, "getClassLoader", "()Ljava/lang/ClassLoader;");
jobject class_loader_obj = env->CallObjectMethod(activity_obj, get_class_loader_mid);

// Use the ClassLoader to load the custom class:
jclass class_loader_class = env->FindClass("java/lang/ClassLoader");
jmethodID find_class_mid = env->GetMethodID(class_loader_class, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
jstring custom_class_name = env->NewStringUTF("fully.qualified.name.of.CustomClass");
jclass custom_class = reinterpret_cast<jclass>(env->CallObjectMethod(class_loader_obj, find_class_mid, custom_class_name));
env->DeleteLocalRef(custom_class_name);

// Now custom_class can be passed to various 'Call<...>Method' calls.
Comment

PREVIOUS NEXT
Code Example
Cpp :: CREDSCORE codechef solution 
Cpp :: online c++ graphics compiler 
Cpp :: MPI_File_seek 
Cpp :: qt widget list set selected 
Cpp :: total sales in array c++ two dimensional array 
Cpp :: frc limelight tracking 
Cpp :: converter python to c++ code 
Cpp :: c++ to c converter 
Cpp :: tutti i tipi di equazioni trigonometriche 
Cpp :: qrandomgenerator bounded 
Cpp :: executing linux scripts 
Cpp :: operator = overloading c++ 
Cpp :: what is c++ function 
Cpp :: combination sum iv leetcode 
Cpp :: how to write hello world c++ 
Cpp :: add for input output file in c/c++ 
Cpp :: C++ Assignment Operators 
Cpp :: how to put string in array c++ 
Cpp :: c++ influenced 
C :: c colourful text 
C :: c check if file exists 
C :: how to use gets after scanf 
C :: how to print boolean in c 
C :: lerp function c 
C :: fonction recursive successeur nombre chaine de caractere en c 
C :: que es % en c 
C :: reverse list in C 
C :: c binary search 
C :: Array Input/Output in C 
C :: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration] 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =