开发者

Providing a background service for other apps

开发者 https://www.devze.com 2022-12-31 09:18 出处:网络
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 andr

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 possibl开发者_运维百科e with the existing sdk?


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.


Hi and welcome to android development. I hope you enjoy your stay :D. About your question:

What you are asking is done with a Service. If you want apps to register for events what is usually done is the following:

  • Create the service with all the logic.
  • Make the service send a Broadcast msg.
  • All interested apps will have a receiver class to get that msg.

I would like to know what you are trying to do to give you further assistance.

0

精彩评论

暂无评论...
验证码 换一张
取 消