Updating user interface from background thread using native code (without JNI)?

I am writing an Android application that does most of the processing in the background thread. The calculations are performed in native code using C ++. I want to update the interface with partial results during the calculations.

I can do this through JNI, namely to set a reference to a UI object in java, and then call the method of this object from native code via JNI. I am looking for a more efficient solution without any JNI calls in terms of rendering (basic setup and activation entry point must be in java).

Is it possible to completely change the executable stream from the background to the user interface in native code without using JNI (only in terms of rendering)?

Thank you for your responses. Very grateful.

EDIT: I am considering using OpenGL to render computed content (kind of video frames) in my opinion. In this case, I probably want to use the method eglSwapBuffers()available in the EGL library since version 2.3. The biggest problem, I think, is how easy it is to switch from a background stream of "computing" to a stream of "open GL" in user code without JNI overhead. What would you suggest? Thank you for your help!

PSEUDOKOD: Here is some kind of pseudo-code that helps illustrate what I want to achieve here. This is more like a threading issue, but the Android framework also plays a role.

// background thread
void Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
                                                  jobject thiz)
{
    //long calculation
    struct result * res = calculate();

    //want to update ui using opengl on ui thread
    updateGL(res);
}


//want to run it on ui thread as opengl can be run only on ui thread
void updateGL(struct result * res)
{
    //some opengl code with "res"
    someGLcodeWithResult(res);

    //render surface
    eglSwapBuffers();
}

2: , . updateGL . GLSurfaceView Java-. (setRenderer()), onDrawFrame JNI/native-. , , , JNI.

-. updateGL java/JNI ( ). , updateGL ( OpenGL) Java. ?

+5
4

. , :

STABLE-APIS.html NDK, :

> V. Android-9 API:

API- , Android > 2.3 .

EGL:

EGL OpenGLES . .

http://www.khronos.org/egl

, :

- List supported EGL configurations
- Allocate and release OpenGLES surfaces
- Swap/Flip surfaces for display  (eglSwapBuffers)

, Android-9, EGL lib . ( , :))

0

Mozilla Fennec. Java/JNI, Android, ( ol ' Mozilla)

+2

, .

  • ++ native
  • java VM

++ Java VM, . - . , , . JNI , , IPC, .

+1

JNI?

.

0

All Articles