문제

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