I am trying to run a service that polls the server every ten seconds and broadcasts the intent. I tried using Thread.sleep(10000) but that dint work. I found out about this START_NOT_STICKY constant used in the service. But I am unable to figure how do I use it. Can someone please help.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
handleStart(intent, startId);
return START_NOT_STICKY;
}
Please make this user-configurable, including supporting “never poll”.
I would recommend the use of
AlarmManagerand anIntentService, so your service code can shut down and get out of RAM between polls. That is not a great solution for running code every 10 seconds, but I am hopeful that your users will reconfigure your app to poll at a more graceful pace, since polling a server every 10 seconds will be expensive in terms of battery and bandwidth usage.This does not have much to do with polling a server every 10 seconds.