Skip to content Skip to sidebar Skip to footer

How To Make Threads Work In Series

I have created a CameraApp. And getting byte[] cameraPreviewCallback in onPreviewFrame(byte byteArray[] , Camera camera) I am converting these byteArray to rgb and doing a lot of s

Solution 1:

Solve it in the java way! Use the Executor interface along with Runnable.

First, get a ExecutorService (which implements the Executor interface) with Executors.newSingleThreadExecutor(), and then, put your Threads to work.

Example:

publicYourClassextendsActivity {
    // Other methods like onCreate() variable declarations and so on.// ...privatevoidrunOnThread() {
        Executor exe = Executors.newSingleThreadExecutor();
        exe.execute(newRunnable() { 
            publicvoidrun() { 
                // Do whatever you want to do.
            } 
        });
    }
    // Other methods...// ...
}

You can read more about Executorhere.

Or like it was said on the comments, you can take a look at ThreadPoolExecutor and on this tutorial.

Post a Comment for "How To Make Threads Work In Series"