Adapting Library for Android
The library given consists of several parts:
- a network module
- a storage module
- a 'controller' module
They all rely on the former module (storage relies on network, controller relies on storage). Most of the functionality is exposed in controller module.
My first plan was to wrap the whole library in a Service that serves as a Adapter for the Android world. But I found out that Services do not have a way to get a result back. So there is no (reasonable) way to call some of the 'getStuff'-Methods in the Controller Module.
What is the 'Android Way' of doing this?
Edit
The network module has to run continuously in the background cause it handles some ongoing network stuff. (so this should be a service, right?) The storage module listens for events from the network and updates itself. As these are POJOs the storage module is registered at the network module.
In the Android Part of the Application i have several Activities. All of these need to access the storage module. But there is no way to get a reference to it cause it is in the Service part of the application.
I would wrap all required methods in Intent responses, but afaik Service Intents can not be called with a result.
So ... how do i get 开发者_C百科my data from the service into activities?
Android build tools (well, Eclipse) support the notion of libraries. Just like any other Java library, a library might have a bunch of classes, some of them public, that consumers are free to instantiate and call. Other projects in the workspace refer to it and instantiate away. What's wrong with that approach?
EDIT: if the activities are within one app, the library code will be shared by default. Activities within one app all run in the same process (unless explicitly configured otherwise), so whatever underlying code is there, it's all shared.
If the activities are different apps, that's another question. Do you need to share the code, or the data? If just the code, then Android build-time libraries still work, as long as all said apps reside within the same workspace. Only if you need to run a set of apps on top of some shared data you have to employ IPC mechanisms - services, content providers. Another answer is the cloud. Another is shared memory (Android supports it). Yet another is a shared data storage somewhere on the SD card (so that app sandboxing does not get in the way).
Hmm... maybe I should have investigated more into bound services. They seem to do exactly what i want.
精彩评论