Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Providing a background service for other apps

I'm new to Android development and I couldn't find this in the Dev Guide.

I would like to create a background service so that any other app could connect to it and get some data from it. I saw android.app.Service, but it seems that it only allows other apps to ping the service, it doesn't allow them to register for some specific events. I had in mind something like the built in LocationManager and its addProximityAlert or even requestLocationUpdates.

Is anything like this possible with the existing sdk?

like image 528
Matic Avatar asked May 21 '10 08:05

Matic


People also ask

How do you create a background service?

To create a Background Service, (1) create a new Class and have it extend the Service class. (2) Inside the class, override the onBind() and onStartCommand() methods. The onStartCommand() method is called every time we start the service either by calling startService() or startForegroundService().

What is background service app?

A background service performs an operation that isn't directly noticed by the user. For example, if an app used a service to compact its storage, that would usually be a background service.


1 Answers

maybe this sample could help you: RemoteService.

This is the description from android developer site:

Remote Service Controller and Remove Service Binding Demonstrates starting a service in a separate process, by assigning android:process=":remote" to the service in the AndroidManifest.xml file. Shows how those clients can either start/stop it with {@link android.content.Context#startService Context.startService} and {@link android.content.Context#stopService Context.stopService}, or bind and call it with {@link android.content.Context#bindService Context.bindService} and {@link android.content.Context#unbindService Context.unindService}. Binding is similar to the local service sample, but illustrates the additional work (defining aidl interfaces) needed to interact with a service in another process. Also shows how a service can publish multiple interfaces and implement callbacks to its clients.

like image 108
hara Avatar answered Oct 21 '22 14:10

hara