Question

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?
}
Était-ce utile?

La solution

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.

Autres conseils

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).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top