0

I want to synchronise a local Android database with a remote database on a server somewhere. For now, I want to do this via a REST API with basic HTTP authentication.

I have done some reading and watched the Google I/O 2010 "Developing Android REST Client Applications" video, however I am still a little confused as to which approach will be most suitable for me:

1.) Content Provider + Service

2.) Content Provider + SyncAdapter

3.) Something else?

I have already written a Content Provider. I am a bit confused about the SyncAdapter and how authentication works - can I used basic HTTP authentication with a SyncAdapter?.

Umbungu
  • 945
  • 3
  • 10
  • 30

1 Answers1

1

Authentication is done with accounts in Android. Have a look at this class: https://developer.android.com/reference/android/accounts/AbstractAccountAuthenticator.html

Also have a look at this blog post: http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-1/

Regarding which approach to choose: If you want to sync between a remote DB and a local DB (that is you really want to sync and not only download content) a sync adapter is always the best choice!

If you have downloaded Android's samples you should also dig into the SampleSyncAdapter project. This should get you started.

BTW: Never ever do Basic HTTP authentication. This is not encrypted and all communication between your server and the app is readable to all. Always use TLS (SSL) instead!

Wolfram Rittmeyer
  • 2,402
  • 1
  • 18
  • 21
  • 1
    Thanks - I wrote "for now" as I just want to use basic http auth during development to get things up and running and then move onto a better approach. – Umbungu Oct 29 '12 at 10:44
  • 1
    Ah, okay, I missed this "for now"- Sounds much better that way :-) I will strip those "bold" markers in my answer. – Wolfram Rittmeyer Oct 29 '12 at 11:01