You need to go through the usage of a SyncAdapter
with combination of a Service
.
Here is a good tutorial (based on Google I/O) to help you get started and working. Also the video shown provides good explanation of a sync adapter.
This is another good one.