错误:can’t instantiate class IntentService no empty constructor

     IntentService 服务的原理,就是启动一个服务,然后开启一个工作线程,当工作线程执行完后,服务就会自动销毁,这种方式可以有效的运行超大时间的工作代码,非常有用,但是在编写的时候出现了一个错误,错误的原因就是没有在super.("这里")指定一个服务名.
public class TestIntentService extends IntentService {
 private static final String TAG = "TestIntentService";
 /**
 * Creates an IntentService. Invoked by your subclass's constructor.
 */
 public TestIntentService() {
 super("TestIntentService");//原来是需要指定一个服务名称
 }

QQ截图20160605142225

Logcat的日志:

06-05 02:21:53.285 21618-21618/com.lanxin.testreceiver I/TestReceiver: before3
06-05 02:21:53.305 21618-21618/com.lanxin.testreceiver I/TestReceiver: after:3
06-05 02:21:53.475 21618-21618/com.lanxin.testreceiver D/TestReceiver1: main:(id)1:(priority)5:(group)main
06-05 02:21:53.475 21618-21618/com.lanxin.testreceiver I/TestReceiver1: 测试一条消息:2
06-05 02:21:53.575 21618-21618/com.lanxin.testreceiver D/TestReceiver1: main:(id)1:(priority)5:(group)main
06-05 02:21:53.595 21618-21618/com.lanxin.testreceiver D/TestReceiver2: main:(id)1:(priority)5:(group)main
06-05 02:21:55.595 21618-21618/com.lanxin.testreceiver I/TestReceiver2: 测试一条消息:2
06-05 02:21:55.595 21618-21618/com.lanxin.testreceiver D/TestReceiver2: main:(id)1:(priority)5:(group)main
06-05 02:21:55.715 21618-21618/com.lanxin.testreceiver I/TestIntentService: Service onCreate
06-05 02:21:55.715 21618-21618/com.lanxin.testreceiver I/TestIntentService: Service onStartCommand
06-05 02:21:55.745 21618-22366/com.lanxin.testreceiver D/TestIntentService: IntentService[TestIntentService]:(id)109:(priority)5:(group)main
06-05 02:21:55.745 21618-22366/com.lanxin.testreceiver I/TestIntentService: onHandleIntent:0
06-05 02:21:55.755 21618-22366/com.lanxin.testreceiver D/TestIntentService: IntentService[TestIntentService]:(id)109:(priority)5:(group)main
06-05 02:21:55.755 21618-22366/com.lanxin.testreceiver I/TestIntentService: onHandleIntent:1
06-05 02:21:56.015 21618-21618/com.lanxin.testreceiver I/TestIntentService: Service onDestroy

 

Leave a Comment

 
Copyright © 2008-2021 lanxinbase.com Rights Reserved. | 粤ICP备14086738号-3 |