I want to implement a service that its task is to periodically retrieve updates from the Internet. I know that there are several ways to achieve this. I list 2 of them. Please tell me which is more efficient and in practice which way is more common. thanks in advance
1. Implement an infinite while (true) loop inside a separate thread, and then run this thread in the service onStartCommand. pseudo code:
class Updater extends Service {
...
public int onStartCommand(Intent intent, int flags, int startId) {
new Thread(new Runnable() {
@Override
public void run() {
while (true){
Thread.sleep(FOR_A_WHILE);
}
}
}).start();
}
...
}
2.Schedule AlarmManagerto run periodically IntentService, which retrieves the update
source
share