I have a table called student which I want to populate from the server. In my activity I show a progress bar and call ContentProvder.requestSync(Content URI of student..). Now if I understand correctly as per Virgil’s talk I should add an observer on the ContentURI of the student to be notified later by the ContentProvider when the sync finishes. But what happens if say there was a network error. The student table will never be populated and my progress dialog will never be removed.
I understand the
“broadcast receiver approach”
mentioned in another thread but that deviates from Virgil’s approach which I consider ideal.
Also on those lines why doesn’t the requestSync allow to pass a ResultReceiver as part of the extras. Isn’t that generally a Service talks back to an Activity?
A SyncAdapter is not meant to be used for this kind of scenario.
SyncAdapteris meant for background sync of data, invisible to the user.Your case sounds like perfect for a AsyncTask. With that you can use
publishProgress()to update your progress bar while your network task happens in another thread. You can find a lot of information and examples onAsyncTaskonline.Example from the link above:
run it by executing it like so:
Here is another example, with tutorial (simply found by google):
http://androidresearch.wordpress.com/2012/03/17/understanding-asynctask-once-and-forever/