Android:IntentService自己启动

时间:2013-10-22 20:23:28

标签: android android-intent intentservice

扩展IntentService的类可以调用startService()来重新启动吗?

public class testService extends IntentService{

public testService (String name){
   super(name);
}

onHandleIntent(Intent intent){

   startService(testService.class); //CAN YOU DO THIS?
}

2 个答案:

答案 0 :(得分:0)

我认为答案是肯定的。

启动服务全部取决于您拥有的上下文类型(http://www.doubleencore.com/2013/06/context/

IntentService和常规服务之间的唯一区别在于它在完成时会自动终止,并且它还会生成一个后台线程,以便您可以进行长时间的操作(如网络)。

答案 1 :(得分:0)

答案是肯定的。我使用相同的模式进行longpoll操作。 不会有任何堆栈溢出,因为从系统的角度来看,它不是递归。 虽然最好在一段时间后使用AlarmManager重新启动服务以节省电量。