Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to/not to use a sync adapter

Tags:

java

android

sync

I'm trying to figure out whether I need to use a sync adapter in my android app.

Procedural Approach Example:

  1. (WITH network coverage) Changes made by a user will automatically be sent to the server.
  2. (WITHOUT network coverage) Changes will be saved in an sqlite table and wait for an online broadcast to upload changes.
  3. Changes sent to server will be saved to an sqlite table mirroring to some extent what is on the server.
  4. Changes on the server will use the C2DM framework to notify users of changes.
  5. When app recieves notification it will fetch the necessary data from the server and update the sqlite tables.

Question is, should I use a sync adapter for this work? If so what would be the high level approach based on my example above. Thank you.

like image 613
HGPB Avatar asked Jun 04 '12 00:06

HGPB


2 Answers

What server application do you want to sync with? If your app wants to synchronize user data with a server, C2DM (using the sync adapter) can be the way to go. It does provide overhead. I find that in most cases, a simple restful interface is easier to create and maintain.

If you want a more detailed answer, you'll have to provide more information on your app.

like image 71
Christine Avatar answered Nov 09 '22 18:11

Christine


If you don't care battery draining, use SyncAdapter to do periodic bidirectional syncing(down and upstream) and modify only local db to interact with user's action. This way you only need two scripts on server side, one for downstream syncing and the other for upstream syncing.

Of course you need have

1). 3 flags, i.e. insert_state, update_state and delete_state for local db to indicate dirty data.

2). uuid for both local and remote db

GoogleIO RESTFUL SYNCING Reference: http://www.youtube.com/watch?v=xHXn3Kg2IQE

like image 37
macio.Jun Avatar answered Nov 09 '22 17:11

macio.Jun