Traian
Traian

Reputation: 3003

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).

Upvotes: 3

Views: 2924

Answers (1)

Alex Cohn
Alex Cohn

Reputation: 57203

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.

Upvotes: 2

Related Questions