thanks for your reply, this was indeed very helpful :D
I declared my "callback" function in the .java file with the native keyword:
public class MyJavaClass {
// callback handler to send notifications back to c++
public static native void StringChanged(String mystring);
public void doSomeStuff () {
// do stuff, then emit changes back to c++
StringChanged("my new string");
}
}
Then I registered those functions in my implementation
void StringChangeReceived(JNIEnv *env, jobject obj, jstring newstring) {
Q_UNUSED(obj)
QString qString(env->GetStringUTFChars(newstring, 0));
qDebug().noquote().nospace() << "callback from Android received: " << qString;
// to be able to emit the changes I either need an instance or (what I decided) a classic singleton
if (nullptr != instance) {
instance->myStringChanged(qString);
}
}
void init () {
// install callback for notifications received
QAndroidJniEnvironment env;
JNINativeMethod methods[] = {
{
"StringChanged",
"(Ljava/lang/String;)V",
reinterpret_cast<void*>(StringChangeReceived)
}
};
QAndroidJniObject javaClass("path/to/my/JavaClass");
jclass objectClass = env->GetObjectClass(javaClass.object<jobject>());
env->RegisterNatives(objectClass, methods, sizeof(methods) / sizeof(methods[0]));
env->DeleteLocalRef(objectClass);
}
With this I realised at least a most basic full roundtrip, from my qml -> over the c++ class -> to the native java class on the android device -> and back over c++ -> to qml. :DDD
Is it common practice to use that in combination with singletons? (Because I think I need them everywhere because of the static call?)
Are there best practices or key values to that kind of implementation?
best regards
an thank you very much,
SyntaX