Domanda

Anyone knows why does the Bluetooth socket shut down automatically when the app tries to take photo using Camera Activity?

The Bluetooth service is bound to the Camera Activity.

Thanks in advance!

È stato utile?

Soluzione 2

If this happens in a custom camera activity, I suspect multithreading (or actually, lack thereof). If you open the camera on the UI thread, then pictureTaken() callback will also be called on the same thread, freezing the UI (unpleasant, but maybe tolerable), and also any BT service communication, which may be lethal for the latter.

The first cure would be to take communications with BT to secondary thread, because there may be other interlock conditions, too.

Second, open the camera on a secondary event thread (see an example), and then the camera callbacks will not freeze the UI and services that use the UI thread.

Altri suggerimenti

Your activity may be destroyed when Camera activity takes the screen. One of the reasons is memory constraints, and there is little you can do about this. Another reason could be that your activity gets restarted for landscape orientation (note that the Camera activity is fixed to landscape). When your activity is gone, the service has no reason to stay alive.

The ways to fix it are: use "custom camera" inside your app; make sure your activity handles orientation change without restart; arrange the BT service to persist even if the activity is destroyed.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top