a 会创建独立的worker 线程来处理所有的intent请求
b会创建独立的worker线程来处理onHandleIntent方法实现的代码,无需处理多线程问题
c所有的请求处理完成后intentService会自动停止,无需调用stopSelt() 方法停止servicein
intentService
package com.yifei.myapplication;
import android.app.IntentService;
import android.content.Intent;
import android.content.Context;
import android.util.Log;
public class MyIntentService extends IntentService {
public MyIntentService() {
super("MyIntentService");
}
@Override
protected void onHandleIntent( Intent intent) {
Log.d("MyIntentService", "打印线程的ID"+Thread.currentThread().getId()
);
}
@Override
public void onDestroy() {
Log.d("MyIntentService", "onDestroy: ");
}
}
activity
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,MyIntentService.class);
startService(intent);
}
});