1、问题列表
1.1、service是运行在一个单独的线程?
官方原文:
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). This means that, if your service is going to do any CPU intensive work or blocking operations (such as MP3 playback or networking), you should create a new thread within the service to do that work. By using a separate thread, you will 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中做一些耗时的操作,需要自己另外启一个线程。
1.2、service可以同时被startService()和bindService()启动吗?
官方原文:
These two paths are not entirely separate. That is, you can bind to a service that was already started with
startService()
. For example, a background music service could be started by calling
startService()
with an
Intent
that identifies the music to play. Later, possibly when the user wants to exercise some control over the player or get information about the current song, an activity can bind to the service by calling
bindService()
. In cases like this,
stopService()
or
stopSelf()
does not actually stop the service until all clients unbind.
一个service可以同时被startService()和bindService()
1.2、service的声明周期
2、demo
2.1、范德萨
3、相关链接
3.1、官方
Guide(Service):http://developer.android.com/guide/components/services.html#Notifications
Guide(BoundService):http://developer.android.com/guide/components/bound-services.html