package com.imooc.intentservicetest;
import android.app.IntentService;
import android.content.Intent;
public class MyIntentService extends IntentService {
/**
* Creates an IntentService. Invoked by your subclass‘s constructor.
*
* @param name Used to name the worker thread, important only for debugging.
*/
public MyIntentService(String name) {
super(name);
}
public MyIntentService() {
super("MyIntentService");
}
@Override
protected void onHandleIntent(Intent intent) {
}
}
@Override
protected void onHandleIntent(Intent intent) {
}<service android:name=".MyIntentService"
android:exported="false"/>package com.imooc.intentservicetest;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = null;
for (int i = 0; i < 10; i++) {
intent = new Intent(this, MyIntentService.class);
intent.putExtra("xys", "" + i);
startService(intent);
}
}
}
05-13 17:14:53.515 19991-20011/com.imooc.intentservicetest D/xys﹕ onHandleIntent0 05-13 17:14:55.528 19991-20011/com.imooc.intentservicetest D/xys﹕ onHandleIntent1 05-13 17:14:57.540 19991-20011/com.imooc.intentservicetest D/xys﹕ onHandleIntent2 05-13 17:14:59.544 19991-20011/com.imooc.intentservicetest D/xys﹕ onHandleIntent3 05-13 17:15:01.556 19991-20011/com.imooc.intentservicetest D/xys﹕ onHandleIntent4 05-13 17:15:03.569 19991-20011/com.imooc.intentservicetest D/xys﹕ onHandleIntent5 05-13 17:15:05.570 19991-20011/com.imooc.intentservicetest D/xys﹕ onHandleIntent6 05-13 17:15:07.574 19991-20011/com.imooc.intentservicetest D/xys﹕ onHandleIntent7 05-13 17:15:09.577 19991-20011/com.imooc.intentservicetest D/xys﹕ onHandleIntent8 05-13 17:15:11.581 19991-20011/com.imooc.intentservicetest D/xys﹕ onHandleIntent9
原文:http://www.cnblogs.com/mengfanrong/p/5080600.html