Can a class that extends IntentService call startService() to start itself again?

public class testService extends IntentService{

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

onHandleIntent(Intent intent){

   startService(testService.class); //CAN YOU DO THIS?
}
有帮助吗?

解决方案

Answer is yes. I use same pattern for longpoll operation. There will not be any stack overflows because is is not a recursion from system's point of view. Although it is better to use AlarmManager to restart service after some time to conserve power.

其他提示

I think the answer is "Yes".

Starting a service all depends on the type of Context you have (http://www.doubleencore.com/2013/06/context/)

And the only Difference between an IntentService and a regular Service is that it automatically kills itself when its done and it also spawns a background Thread so that you can do a long operation (Like Network).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top