Android service java method is returning always same value to Qt Android service

  • 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",

    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.

  • Moderators

    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;
        jobj = QAndroidJniObject::callStaticMethod<jint>("org/qtproject/example_v2/BackService",

  • Unfortunately it didn't work. I still get the same value. Any other suggestion?