Skip to content Skip to sidebar Skip to footer

Android Application As A Service Without Activity

I am making a set of apps and I have pretty much the same background service for all of them. I'm trying to make an app that has only this Service. so I don't repeat it in all of t

Solution 1:

Sure! No reason you cannot have an application with only a service. ...and no need to get into AIDL unless you want to.

The problem is, how to make the application run. When you create an application with an Activity, you add an Intent filter, in the manifest, that makes the activity startable from the Launcher. If there's no activity, you'll have to find another way to start it.

It is easy to do, though. Just fire an intent from one of your other programs, like this:

startService(newIntent("my.service.intent"));

... where the service is registered your manifest, like this:

<serviceandroid:name=".SomeService" ><intent-filter><actionandroid:name="my.service.intent"/></intent-filter>

You could use that intent to pass Parcelable parameters to the service, and the service can reply by broadcasting intents back.

Of course startService and broadcastIntent are a bit clunky if you really need a complex API between applications and your service. If you need something richer, you will want to look into AIDL and a Bound Service.

Edited to add Intent Filter

Post a Comment for "Android Application As A Service Without Activity"