接上文:
段落一:Although this documentation generally discusses started and bound services separately, your service can work both ways—it can be started (to run indefinitely) and also allow binding. It's simply a matter of whether you implement a couple of callback methods: onStartCommand()
to allow components to start it and onBind()
to allow binding.
service 是直接启动还是bind随你便。
如果是直接启动的话就要实现onStartCommand()方法
绑定的话就要实现onBind()方法
段落二:
Regardless of whether your service is started, bound, or both, any application component can use the service (even from a separate application) in the same way that any component can use an activity—by starting it with an Intent
. However, you can declare the service as private in the manifest file and block access from other applications. This is discussed more in the section about Declaring the service in the manifest.
不管service怎么启动,其他应用组件都能使用它(跨进程也行),----就像是其他组件都能通过Intent使用activity一样。
不过,你也能把service申明为私有,这样别人就不能用了。参考Declaring the service in the manifest.
段落三:
Caution: A service runs in the main thread of its hosting process; the service does not create its own thread and does not run in a separate process unless you specify otherwise. If your service is going to perform any CPU-intensive work or blocking operations, such as MP3 playback or networking, you should create a new thread within the service to complete that work. By using a separate thread, you can reduce the risk of Application Not Responding (ANR) errors, and the application's main thread can remain dedicated to user interaction with your activities.
简译:service默认在主线程(启动它的线程),你要work,自己开线程去。