Mando
Mando

Reputation: 11712

Android library module with extendable service

I need to develop an android library which has a service component. The service requirements are:

The purpose of the service is to provide for any client (android application) which will use it an ability to subscribe for certain events which should be executed in background. Dure to the limitation that extended client should receive notification even in background (even when the client is not started) I can see it as an extension for the service (derived service reconfigured at Manifest at the client app).

What is the most proper approach to achieve my goal? How should base service communicate with the client extension?

Upvotes: 3

Views: 1202

Answers (1)

Gennadii Saprykin
Gennadii Saprykin

Reputation: 4573

So first client will have to add this service to their AndroidManifest.xml. Then client will call some methods from the library that will start your service or alarm service, depending on your needs.

Communication depends on the data you want to send from service to client's app. If it's just a notification then the best way would be to use a BroadcastReceiver. If you register a receiver in AndroidManifest.xml it will receive intents even when the app is not started.

If you want to send a lot of objects or call some method on a service you can use ServiceConnection and binder.

For instance, you need your client to receive a List<Model> from your service even if the client is not started. You declare a BroadcastReceiver in AndroidManifest.xml which will receive some intent depending on its intent filter. Then you bind to your service via ServiceConnection and pass a callback object. After that you start a background thread inside your service to load data. Once it's done, you call a callback method and your client app will receive the data.

Not sure if I answered your question because it's a bit abstract.

Upvotes: 1

Related Questions