Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android camera running on AsyncTask

Does anyone have a working sample of such "thing"?

In theory it's a good idea to implement it this way but I didn't see any relevant piece of code which shows how to implement it.

I don't want anything fancy, the simpler the better. I just want to have everything related to camera control implemented on a separate thread.

Thanks

[edit]

more specific: like the official documentation states, "the recommended way to access the camera is to open Camera on a separate thread that's launched from onCreate()". Therefore what I need is a minimal implementation of a CameraPreview class extending AsyncTask (I assume).

like image 433
Traian Avatar asked Apr 15 '26 20:04

Traian


1 Answers

Your quote is IIRC, incomplete. The recommendation is There are two reasons to offload camera.open() to a secondary thread. One is that open() itself is slow on some devices. But camera callbacks will still arrive on the main thread.

If you don't want to receive camera callbacks on the UI thread, you should open the camera on a separate event thread (emphasis mine). Event thread is also known as Looper thread.

Therefore AsyncTask cannot help here. See https://stackoverflow.com/a/19154438/192373 for a working example.

like image 64
Alex Cohn Avatar answered Apr 18 '26 09:04

Alex Cohn