Reputation: 3936
ok I have this application which needs to send periodic updates to a web-service, I have done a fair amount of research and I've come up with two service implementation patterns.
Implement a service with a thread, the periodic update time may vary therefore, I will put the thread to sleep with the required time-interval, then call the web-service again. I also need to update an activity, therefore will be using a broadcast receiver or a messenger.
Use a Service with a schedule timer/alarm manager, wake the system and use intent services coupled with a broadcast receiver.
Which would be the best approach?
Upvotes: 0
Views: 130
Reputation: 7120
I think I would go with the #2 option :
IntentService
to do the update.BroadcastReceiver
with IntentFilter
(s) and start the IntentService
from it.AlarmManager
to Broadcast
the registered action at the required time intervals.I prefer this method because :
IntentService
Upvotes: 2
Reputation: 36836
The main difference would be that a background service can be shut down by the user and then you won't get any more updates. If you register events with the AlarmManager, then you control when/if these events take place. If the user shuts down your app and goes into a task manager and shuts down any running services related to your app, the AlarmManager is still going to wake up and send a message that your BroadcastReceiver will receive.
Upvotes: 0