IntentService使用一个工作队列来从Application的主线程中分担任务,这些任务往往做着比较耗时的工作。IntentService维护着一个工作线程消息处理对象(Handler),通过在工作线程中创建消息循环(Looper)和消息队列(MessageQueue)来以队列的方式处理任务,一次只能处理一个任务,上一个任务请求完成后才接着处理下一个任务请求。
IntentService继承自Service,也就是说IntentService具有Service的一切特性。客户端可以通过startService(Intent) 来发送一个任务请求,如果IntentService还未创建的话,会调用onCreate()方法
@Override
public void onCreate() {
// TODO: It would be nice to have an option to hold a partial wakelock
// during processing, and to have a static startService(Context, Intent)
// method that would launch the service & hand off a wakelock.
super .onCreate();
HandlerThread thread = new HandlerThread("IntentService[&