Android service java method is returning always same value to Qt Android service
-
wrote on 9 Feb 2019, 11:56 last edited by
I'm trying to return value to Qt service from java service code. Java always returns initial value for variable. However when I run same code in Qt main activity, it is working.
Code in BackService java class:
public static int SAYK = 0; public static void callNorm(int valSy) { BackService.SAYK = valSy; System.out.println("Result= "+BackService.SAYK); } public static int retStt() { return BackService.SAYK; }
C++ code in Qt Service:
int jobj = QAndroidJniObject::callStaticMethod<jint>("org/qtproject/example_v2/BackService", "retStt", "()I");
When I call "callNorm" function from java, system prints new value of SAYK. But when I call "retStt" from Qt service, it returns only initial value 0. I tried also with callStaticObjectMethod, getStaticField, java native functions(gives unsatisfied link error) etc. Unfortunately, none of these worked. Also I can call java functions that has not return value from Qt Service, without problems.
-
I'm trying to return value to Qt service from java service code. Java always returns initial value for variable. However when I run same code in Qt main activity, it is working.
Code in BackService java class:
public static int SAYK = 0; public static void callNorm(int valSy) { BackService.SAYK = valSy; System.out.println("Result= "+BackService.SAYK); } public static int retStt() { return BackService.SAYK; }
C++ code in Qt Service:
int jobj = QAndroidJniObject::callStaticMethod<jint>("org/qtproject/example_v2/BackService", "retStt", "()I");
When I call "callNorm" function from java, system prints new value of SAYK. But when I call "retStt" from Qt service, it returns only initial value 0. I tried also with callStaticObjectMethod, getStaticField, java native functions(gives unsatisfied link error) etc. Unfortunately, none of these worked. Also I can call java functions that has not return value from Qt Service, without problems.
Moderatorswrote on 9 Feb 2019, 18:24 last edited by raven-worx 2 Sept 2019, 19:02@ismail
IIRC since you calling from Qt (which runs in a separate thread) you get separate static variables other than the java thread.Try if that works for you:
jint jobj; QtAndroid::runOnAndroidThreadSync([&jobj](){ jobj = QAndroidJniObject::callStaticMethod<jint>("org/qtproject/example_v2/BackService", "retStt", "()I"); });
-
wrote on 10 Feb 2019, 11:55 last edited by ismail
Unfortunately it didn't work. I still get the same value. Any other suggestion?
3/3