Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Status
titleJAVA

Status
colourYellow
titleC++

public class Database{
public static native String GetName( int id );

}

String name = Database.GetName(1);

JNIEXPORT jstring JNICALL Java_com_domain_Database_GetName( JNIEnv * env, jclass clazz, jint id )
{

CFxJavaString name( L"John Doe" );
return name.GetStrongJString();
}

public class Database{
public static native String[] GetPairGetNames( int id );

}

String[] pair = Database.GetNames();

JNIEXPORT jobjectarray JNICALL Java_com_domain_Database_GetPair( JNIEnv * env, jclass clazz )
{
jclass stringClass = GET_JAVA()->FindClass( "java/lang/String" );
CFxJavaObjectArray names( layouts.size(), stringClass );

CFxJavaString name1( “John Doe“ );
CFxJavaString name2( “Mr. Allister“ );
names.SetElement( 0, name1.GetStrongJString() );
names.SetElement( 1, name2.GetStrongJString() );

return reinterpret_cast<jobjectArray >( names.GetStrongJObject() );
}

Note: If an object is passed as return value back to Java, it is always necessary to use methods like GetStringJStringGetStrongJString() or GetStringJObjectGetStrongJObject() else there might runtime errors occur. These methods warrant the life time of an object even when the C++ method is being taken from call stack. For further samples look for any use of CFxStaticInvocation and CFxObjectInvocation in the SDK Android projects.