Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Sync Sqlite

I am making a dictionary kind of an app which uses SQLite. I have a single table that keeps the pair of foreign words and their translations. I want to sync this table with a particular spreadsheet in Google Docs.

I ve found this awesome library to retrieve and manipulate GoogleSpreadsheets, so at least I am covered for that. But I donT feel comfortable about the sync. Now,

  1. Can I use a SyncAdapter to do this sync between my SQLite and a GoogleSpreadsheet? If yes, how would I go about it? Would I retrieve and manipulate the rows of the spreadsheet in the onPerformSync or smth?
  2. What could be the other alternatives for such a scenario? Should I maybe use a normal service to do the check when the user requests it (in the main activity, for example) ?

On the Google I/O vids (particularly on Android REST client apps ) they seem pretty persuasive for using the SyncAdapter but I am not sure if it could help me without an actual REST service.

Thanks in advance..

like image 621
Orkun Ozen Avatar asked Mar 08 '12 22:03

Orkun Ozen


1 Answers

One good reason to use the Android SyncAdapter, ContentProvider and SyncManager is that you will benefit from the Google system knowledge that is useful for preserving battery life and other resources. Some of this content is in the video you link to. For example, exponential back-off logic to prevent wasteful attempts at synchronizing.

There is some good info about battery life preservation by conserving cell radio power in today's Google I/O 2012 talk "Making Good Apps Great: More Advanced Topics for Expert Android Developers." While not mentioned explicitly, I think that the SyncManager is likely to have the battery conserving properties that are mentioned in this video.

Based on my reading (not actually implementing anything) of the APIs and other resources such as the com.example.android.samplesync package, it seems that the pattern is flexible enough to adapt to your program needs.

The team I'm working with has implemented custom sync for our android app but I can tell you we didn't consider this option because we were committed to writing as much logic as possible to run with the WebView. I wouldn't necessarily recommend that, but that's beyond the scope here.

like image 127
James Avatar answered Oct 01 '22 02:10

James