1

I'm writing a Bluetooth remote control application to control my Bluetooth enabled robot, but I have a hard time understanding the workflow of an Android application. I know what I want, but it's not very easy to do. Other responses haven't been satisfactory.

Here's a rough application layout I want:

enter image description here

If you have a better idea of how to do this thing I'd be happy to consider.

Mainly my problem is accessing the connection thread/service (whatever the name is) from the connect method of the main activity and from the control activity, how do I pass the reference? I know that the main activity can disappear when in a sub-activity of the application, so I'd have to pass the reference by getExtra() probably, but it only takes a String variable...

4

1 に答える 1

1

検討したい方法の 1 つは、バインドされたサービスを使用することです。これにより、サービスのパブリック メソッドへのアクセスを許可するIBinderインターフェイスを返すことができます。任意のアクティビティをサービスにバインドして、サービスとの間でデータのやり取りを行うことができます。

サービスがアクティビティとすぐに通信する必要がある場合 (接続が失われた場合など)、サービスはsendBroadcastを使用して、ブロードキャストで送信されたインテントをリッスンするBroadcastReceiverを登録したアクティビティに通知できます。

于 2012-08-04T11:00:43.303 に答える