tags:

views:

31

answers:

1

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;
    }
+1  A: 

I am trying to run a service that polls the server every ten seconds

Please make this user-configurable, including supporting "never poll".

I tried using Thread.sleep(10000) but that dint work.

I would recommend the use of AlarmManager and an IntentService, 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.

I found out about this START_NOT_STICKY constant used in the service.

This does not have much to do with polling a server every 10 seconds.

CommonsWare
Thank you CommonsWare. Are you aware of any good tutorials that teach the AlarmManager and IntentService stuff.
raqz
http://github.com/commonsguy/cwac-wakefulfound this... but dint help much
raqz
@raqz: The project you link to above is for a reusable component that demonstrates an `AlarmManager`/`IntentService` combination, designed to allow the service to do its work even if the phone might otherwise want to fall asleep. In terms of tutorials, I'm sure there are some out on the Internet, though I do not know of any. I cover the pattern in a couple of books.
CommonsWare
@CommonsWare...thanks ..i will search again..hope to find some more :)
raqz
http://www.brighthub.com/mobile/google-android/articles/34861.aspxtried using this method..but it doesnt work
raqz