8

I'm a newb with the syncAdapter . i've watched the google IO video (lecture presentation here) , and i've read 2 tutorials (here and here) about it .

i've also tried out the code of the tutorials and it's frustrating that i can't figure out how to implement the syncAdapter correctly .

what i believe is that some of the preferences (either in the manifest or on the xml files) are just wrong , but i can't find out why .

i've succeeded to allow adding the syncing account and also show it with its icon .

however , i'm facing some weird problems that i can't figure out why they occur:

  1. allow the account to synchronize . the end user cannot press on the syncing button . it also doesn't seem to auto-sync even though i've tried to add such a thing upon adding the account .

  2. after adding the account , the end user can see a weird description of the account : "res/xml/authenticator.xml" . not sure where its being set.

  3. when clicking the account (after it was added) , i see an empty list (which is proba. how do i add more items there ? in the future , i need to also sync with facebook and gmail , but i can't event succeed with adding my own contentProvider to this list.

i don't need to do real authorization so i just use the next code instead inside the activity that extends from AccountAuthenticatorActivity :

accountManager.addAccountExplicitly(account, PASSWORD, null);
final Intent intent = new Intent();
intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, USERNAME);
intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, accountType);
setAccountAuthenticatorResult(intent.getExtras());
setResult(RESULT_OK, intent);
finish();

i've also tried to set auto-syncing and enable syncing by using what's described here.

Community
  • 1
  • 1
android developer
  • 114,585
  • 152
  • 739
  • 1,270

1 Answers1

0

About 1) yes you can't sync if there isn.'t an internet connection. The reason is that (although there isn't a proper definition of a sync adapter) a sync adapter is a component that is supposed to be used to sync a backbone with your local data. If there is no connection it does not make sense to start the sync. Actually this is true only in theory becausr I had to develope a sybc adapter even if there was no backbone database.

What I did was to write a component that is called by the sync adapter when it is triggered and by my own application when the sync is necessary even if there is no connection

kingston
  • 11,053
  • 14
  • 62
  • 116
  • Take into considerstion that the framework automatically handle the multiple sync request. If you develop youe own component you need to do it by yourself. – kingston Jul 25 '12 at 17:21
  • i don't understand the last comment. also , is it possible to communicate with other syncAdapters (with the right permission , of course) , for example to get the credentials needed to fetch data from them or communicate with their servers ? the question is on another post i've recently written : http://stackoverflow.com/questions/11532257/android-use-syncadapter-to-sync-with-gmail-data-and-facebook-data – android developer Jul 25 '12 at 17:37
  • About my previous comment. Suppose that the user clicks twice on the sync button very quickly. The framework try to avoid sending the request twice. If the components of your application that trigger the sync can make multiple requests you need to do something similar. For example in my application if a second request comes while the sync is still ongoing I drop the current sync and I start a new one. If a thirdrequest comeswhileI'm dropping the first one and starting the second one I ignore the third request etc. You need to implement your own strategy for for optimizing the sync – kingston Jul 25 '12 at 17:44
  • i see . how do you know that it's in the middle of syncing , and how do you listen to the events of during-syncing and stopped-syncing inside the app and inside the syncAdapter ? – android developer Jul 25 '12 at 17:47
  • This is part of your application logic. You need to handle it with a state machine. – kingston Jul 31 '12 at 08:15
  • yes, i forgot to update this answer as i've found how to do that via: http://stackoverflow.com/questions/6622316/how-to-know-when-sync-is-finished/11657333#11657333 – android developer Jul 31 '12 at 08:22