Can everyone explain a little bit regarding cocos thread, jni thread, GLthread, main thread , ui thread ...?

Can everyone explain a little bit regarding cocos thread, jni thread, GLthread, main thread , ui thread ...?
0

Hi all,

Currently I have a little trouble regarding cocos thread, jni thread, GLthread, main thread , ui thread … ?

If I want to integrate third party lib on Android Platform , the best way I should write everything in AppActivity.java to make it run on Main Thread right ? ( for me , I created XXXHepler Class with some public static functions , I don’t know what thread it is working on )

As I know , JNIThread is another thread completely independent from the main thread ! If I want to run the java code in main thread , I need to call :slight_smile:

//context = AppActivity.getContext()
public static void functionNoReturnValue(){
Handler mainHandler = new Handler(context.getMainLooper());
mainHandler.post(new Runnable() {

    @Override
    public void run() {
        // run code
    }
});

but If I want to call one functon with return value in main thread , What should I do ?
Example:

//context = AppActivity.getContext()
public static double functionReturnValue(){

double result = 0.0;
Handler mainHandler = new Handler(context.getMainLooper());
mainHandler.post(new Runnable() {

    @Override
    public void run() {
        // run code
		result = getDoubleFunctionInMainThread();
    }
});

return result; // It always return 0.0
}

Thanks

Keep the “result” in the class variable, e.g. “mResult” and create another static method to get its value. I don’t see any other way to do it. If you are calling methods in different threads then results will not come immediately.

1 Like

Hi , Thanks for your help ! I will check your solution and let you know later !