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

  • Home
  • SEARCH
  • 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 934307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:58:41+00:00 2026-05-15T20:58:41+00:00

So here’s some code on http://groups.google.com/group/android-developers/browse_thread/thread/16a2216b39513674 in which the poster writes that he’s shortened

  • 0

So here’s some code on http://groups.google.com/group/android-developers/browse_thread/thread/16a2216b39513674 in which the poster writes that he’s shortened ideas into a single threaded app. A respondent below his post says, essentially, that’s great, nice work, but there are benefits to multithreading so things don’t interfere with other stuff on your handset.

My question is: Evidently, the original poster reduced, distilled ideas from multithreaded examples he saw in order to make them easier to read, posted them, cool. But what would a multithreaded version of the below code look like?

Would Runnable be on a separate thread? Or the whole callback? Or not those but something else? Anything else?

Would it be even better if it were run as a service, and then a Runnable thread spawned from the service? Is a service considered a separate thread from the UI?

As you can tell this question is about the basics of multithreading for Android. Thanks for any info.

public class Something extends Activity { 
    @Override
    protected void onCreate(Bundle saved) { 
      super.onResume(); 
      final EGL10 egl = (EGL10) EGLContext.getEGL(); 
      final EGLDisplay eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); 
      int[] version = new int[2]; 
      egl.eglInitialize(eglDisplay, version); 

      int[] configSpec = { 
          // EGL10.EGL_DEPTH_SIZE, 8, 
          EGL10.EGL_NONE 
      }; 

      final EGLConfig[] config = new EGLConfig[1]; 
      int num_configs[] = new int[1]; 
      egl.eglChooseConfig(eglDisplay, configSpec, config, 1, num_configs); 
      final EGLContext eglContext = egl.eglCreateContext(eglDisplay, config[0], EGL10.EGL_NO_CONTEXT, null); 

      // Setting up layouts and views 
      SurfaceView view = new SurfaceView(this); 
      setContentView(view); 

      SurfaceHolder holder = view.getHolder(); 
      holder.setType(SurfaceHolder.SURFACE_TYPE_GPU); 
      final GL10 gl = (GL10) eglContext.getGL(); 
      final Handler handler = new Handler(); 

      holder.addCallback(new Callback() {
        private EGLSurface surface; 
        private Runnable painter; 

        @Override 
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { 
          // initialize GL projection and other stuff 
          // gl.glMatrixMode(GL10.GL_PROJECTION); 
          // gl.glFrustumf(left, right, bottom, top, zNear, zFar); 
          // ... 
          painter = new Runnable() { 
            @Override 
            public void run() { 
              drawFrame(gl); 
              egl.eglSwapBuffers(eglDisplay, surface); 
              handler.post(this); 
            } 
          }; 
          handler.post(painter); 
        } 
        @Override 
        public void surfaceCreated(SurfaceHolder holder) { 
          surface = egl.eglCreateWindowSurface(eglDisplay, config[0], holder, null); 
          egl.eglMakeCurrent(eglDisplay, surface, surface, eglContext); 
        } 
        @Override 
        public void surfaceDestroyed(SurfaceHolder holder) { 
          handler.removeCallbacks(painter); 
        } 
      });
    } 

    private void drawFrame(GL10 gl) { 
      // Frame drawing... 
      long t = System.currentTimeMillis() % 10000; 
      gl.glClearColor(t / (float) 10000, t / (float) 10000 ,1 , 1); 
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 
    } 
}
  • 1 1 Answer
  • 2 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-15T20:58:41+00:00Added an answer on May 15, 2026 at 8:58 pm

    Read about AsyncTask in a great article from Google Android Team titled Painless threading

    As with my own words, AsyncTask is an intelligent Thread that has two methods that run on UI thread, so you can update your UI in those methods.

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

Sidebar

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.