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.
Android: IntentService start itself
-
01-07-2022 - |
题
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?
}
解决方案
其他提示
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).
不隶属于 StackOverflow