Krystian Bersztolc
Krystian Bersztolc

Reputation: 204

Strategy for unweight UI thread (Camera.PreviewCallback)

I'm asking for help. I binded service in an acvitity:

Intent i = new Intent(MainActivity.this, X.class);
MainActivity.this.bindService(i, mConnection, Context.BIND_AUTO_CREATE);

This service is designed to decode data from Camera.PreviewCallback (YCbCr_420_SP (NV21)) to RGB. For unweight CPU I limitted framerate and camera resolution. (there isn't live preview).

Problem that I face is overloading UI thread which results slow down showing content on MainActivity (animations, movies). All expensive operations are executing in the service (decoding, reading barcodes).

How can i fix this? I think, that i must create some thread, but how to connect him with Camera.PrviewCallback ?

Thanks and please advice.

Upvotes: 0

Views: 389

Answers (1)

Alex Cohn
Alex Cohn

Reputation: 57203

I have recently explained how an Activity can be modified to take onPreviewCallback() off the UI thread: Best use of HandlerThread over other similar classes. Same approach can be applied to a service.

Upvotes: 1

Related Questions