I am working on an idea for an app and want to really understand what role threads and services will play in my application. In a very simple app, I want a list view to be updated once a week from some sort of database. Ballpark 100 items. So from what I think i understand so far, I will have an activity which will have a UI consisting of a list view. I will then have a service. In this service I will have a thread, and this thread will be in charge of downloading. The service is there simply to make sure the download can continue if the app is paused or stopped. Then I can use a message/runnable/asyncTask to send this data over to my activity/UI from my thread. Am I right in thinking this?
Share
I think you missed a BroasdCastReceiver:
For this task you’ll need to install an Alarm. Alarms usually start Broadcast receivers, to be sure that phone isn’t sleeping. This BroadcastReceiver will have to start your service. I know it sounds complicated, but its quite ok to implement 🙂
Here are my comments for the remaining questions:
Correct
Thats also correct.
That will maybe fail, because your service doesn’t know if the main activity is running. Whats about writing the lists data into a shared file, both service and activity can access?