开通VIP,畅享免费电子书等14项超值服
首页
好书
留言交流
下载APP
联系客服
2010.11.22
public abstract class IntentService extends Service {
...
}
private final class ServiceHandler extends Handler {
public ServiceHandler(Looper looper) {
super(looper);
@Override
public void onCreate() {
super.onCreate();
HandlerThread thread = new HandlerThread("IntentService[" + mName + "]");
thread.start();
mServiceLooper = thread.getLooper();
mServiceHandler = new ServiceHandler(mServiceLooper);
public void onStart(Intent intent, int startId) {
Message msg = mServiceHandler.obtainMessage();
msg.arg1 = startId;
msg.obj = intent;
mServiceHandler.sendMessage(msg);
public void handleMessage(Message msg) {
onHandleIntent((Intent)msg.obj);
stopSelf(msg.arg1);
public void onDestroy() {
mServiceLooper.quit();
微信登录中...请勿关闭此页面