Skip to content
mataanin edited this page Apr 14, 2012 · 2 revisions

This tutorial is intended to explain basic concepts of SensorLib and example ForaApp demonstrating how to use the library.

Code is best documentation. However, you might be interested in the metaphors first.

Metaphors

Driver is an Android Service build according to Remote Messenger Service Sample .

Client is an Activity, Fragments or other Service which registers to exchange Messages with the Driver. Clients of the Driver are identified with a String clientId (e.x. client's Activity classpath).

Messages sent by Driver can be persisted, so that if client is stopped or destroyed, it would still receive a pending Message the next time it registers with Driver.

Driver implements following high-level functionality:

  • register a client
  • register a clients out
  • stop execution after on receiving a message
  • automatically stop execution if idle
Sensor Sink is a Driver, which is handles Bluetooth connectivity with sensors having internal memory of any kind. Currently, it can only act as a SLAVE connecting to Bluetooth HOST sensors.

Sensor Sink is much more capable than just DriverService. It can:

  • connect to a Bluetooth HOST device
  • tell about it's connection status (connected, connecting, disconnected)
  • disconnect
  • tell the number of records
  • send records from specific range filtered by type
Driver Connection implements the interface of a Driver, to be accessed by a client through function calls or sending messages. It has status indicating what is currently being done by the Service and allow to listen for incoming messages. If a connection is unbound (can't send messages to a Service), Driver Connection saves pending messages to be send later.

Driver Connection have following states:

  • bound
  • unbound
Notably, connection becomes bound, only when it can communicate with Service.

Sensor Sink Connection is a Driver Connection. It implements the interface of (surprise, surprise) Sink Sensor. It has following states additionally to ones of Driver Connection:

  • counting
  • downloading

Life-cycle

In order to enable background data connection, both Driver and Sensor Sink can work as Started Service or Bound Service. Choose based on your needs, but mind this short advice:

  • If you want to collect data on the background, use Started Service and start it in Application.onCreate .
  • If you only need to receive/send data, while application is actively used, Bind in Activity.onCreate and Unbind in Activity.onDestroy.
  • If you want to use Fragments, you must bind / unbind in Activity.
Clone this wiki locally