I've been spending the past couple of weeks refactoring a lot of the existing code. The network driver worked, but it relied on the bound Android service running in the same process so that it could access member functions. While I can make that assumption for the network driver, my ultimate goal is to support USB host-connected devices, and that requires Android 3.1 or greater. I didn't want to limit the use of the app for that one feature, and so I chose to isolate the USB code to a separate app. The USB driver would have a service with the same API as the network driver, making it easy to change which was in use without a lot of code changes.
I needed to find a better way to have the activities communicate with the service (either USB or network) that was connected to the TinyG. This communication needed to be bidirectional, and needed to work for multiple activities (screens). What I settled on was using a Messenger to send commands to the service (asking for data, connect, disconnect, etc), and using broadcast intents to send messages from the service to one or more listening activities. This seems to give the most flexibility without a lot of effort. An alternative to the broadcasts would have been client messengers registered on the service end, but it seems like that's a lot of work for little gain.
To make more of the code reusable, I now have three projects on Github. The main application is android-tinyg, and it contains most of the activities and preference code for the application. android-tinyg-usb is a skeleton for the USB code, and requires API level 12 or higher. Both of these rely on code in android-tinyg-support, which has the majority of the JSON parsing, messaging constants, and related items. The TinyGDriver class is an abstraction for both the network and USB drivers, which subclass it.
I'm done with the refactoring, and it looks like the new code works as expected. I hope to have a longer demo from my tablet up soon using the new code, and to have a prepackaged apk up on the site and Google Play soon after.