Pause thread and re run it

32 Views Asked by At

I have an application that use camera. In this application, on some time, I will update the value of UI and will pass to liveData to change the UI. I want to pause the camera thread till to done update UI.

I've tried to sleep the thread but what I expected is it pause till done update UI but sleep a specific time. So please let me know how I can pause the thread of camera and re run it. Here is the creation of camera executor and usage on camera:

val cameraExecutor = Executors.newSingleThreadExecutor()
val imageAnalyzer = ImageAnalysis.Builder()
        .setTargetResolution(Size(binding.viewFinder.width, binding.viewFinder.height))
        .setTargetRotation(binding.viewFinder.display.rotation).setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_RGBA_8888).build().also {
            it.setAnalyzer(cameraExecutor) { image ->
                // handle image here
            }
        }

The expected result that I expected:

fun updateUI() {
    // update liveData so the view observe will change value
    startUpdateUI()
    // pause the thread until UI update done
    // Before I use Thread.sleep(SPECIFIC_TIME) but I want to it will re run right after done update UI 
    // Please help me to handle here
}

fun doneUpdateUI() {
    // re run the thread
}
0

There are 0 best solutions below