Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7028265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:21:53+00:00 2026-05-28T00:21:53+00:00

I am writing an Android application that does much of a processing in the

  • 0

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

I am able to do so through JNI, namely set reference to UI object in java and then call a method of this object from native code trough JNI. I am looking for a more efficient solution without any JNI calls in the rendering part (the basic setup and an activation entry point will have to be in java).

Is it possible to change execution thread from background to UI entirely in native code without using JNI (only in the rendering part)?

Thanks for your answers. Much appreciated.

EDIT:
I am considering using OpenGL to render calculated content (sort of video frames) in my view. In that case I would probably want to use eglSwapBuffers() method that is available in EGL library from 2.3 onwards. The biggest problem is, I think, how to easily switch from background “calculation” thread to UI “open GL” thread in native code without JNI overhead. What would you recommend? Thanks for your help!

PSEUDOCODE:
Here is some pseudocode that helps to illustrate what I want to achieve here. It is more like a threading issue but Android framework comes into play as well.

// 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();
}

EDIT 2:
As the bounty slowly draws to close, one more clarification. There are couple of ways to call the updateGL method above. The most typical one is to use GLSurfaceView in java code. It would require setting a renderer (setRenderer()) and then overriding onDrawFrame with some code to call JNI/native layer. This way for every frame being rendered one JNI call gets executed.

I would like to do the rendering a little differently. I want to call updateGL without using java/JNI code at all and use only the native layer (as presented in the excerpt above). The biggest problem for me now is how to run the updateGL on UI thread (required by OpenGL) without the java callback. Is it at all feasible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:21:53+00:00Added an answer on May 28, 2026 at 12:21 am

    I’m facing the same problem right now. Perhaps this might help:

    When you take a look at the STABLE-APIS.html in the latest NDK it says:

    > V. Android-9 Stable Native APIs:

    All the APIs listed below are available for developing native code that runs
    on Android > 2.3 system images and above.

    The EGL graphics library:

    EGL provides a native platform interface to allocate and manage OpenGLES
    surfaces. For more information about its features, please see:

    http://www.khronos.org/egl
    

    In a nutshell, this will allow you to do the following directly from
    native code:

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

    So if you’re targeting Android-9 then you could try to use the EGL lib in native code.
    (Let me know if this works :))

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I'm writing application for android, using Eclipse in Windows. I'm implementing C code
I'm writing an Android application that I want to be able to send requests
I'm writing an application in PhoneGap that I want to run on iOS, Android,
I have an application I am writing for Android that basically does a screen
Problem Description I am writing application for Android and use native code, And test
I'm writing code for an Android application that is supposed to take data, package
I'm writing an application for android. My problem is that I want it to
In short, I am writing an Android application that I want to have pull
I'm currently writing a application that allows to save drafts (using android version >=
I'm writing an android application that draws directly to the canvas on the onDraw

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.