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?
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().
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With