We are successfully runnning Apache Felix 4.0.3 on Android (2.1) and can deploy/remove Bundles at runtime. For dependeny management between OSGI Bundles we use the Felix DependenyManager.
Now we want to to send data from running OSGI Bundles to the Android GUI and display it.
How can we accomplish this task ? Is there some kind of callback we could use ?
Assuming that by ‘send data’, you mean interacting with the services that bundles provide, there is nothing special about this: just make sure you keep hold of the
BundleContextinstance that yourFelixinstance gives you, and use it to request services. The way you bind your data, is then totally up to you, just as it is in any other Java project.Just showing data
As a rather contrived example, you can do something like
to set up the framework, get some service, and put update the UI with some data.
Binding
There is no default callback you can use, but one trick I particularly like is to make UI elements aware of their OSGi environment; in that way, you can make them ‘listen’ to changes in your framework. Below is a simplified view of what I use, I prefer delegating the complicated stuff to the Apache Felix Dependency Manager.
For instance, say you have some listener interface.
and you have some service that regularly calls all services that implement this interface with the current time. You can now create a
TextFieldthat updates itself every time this method is called. Something like,