Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyncAdapter alternatives

I think its well known that in list of worst-documented topics, SyncAdapter shines bright like a diamond ! acording to http://udinic.wordpress.com/2013/07/24/write-your-own-android-sync-adapter/ SyncAdapter brings 4 main benefits : A) Battery efficiency B) Interface C) Content awareness D) Retry mechanism;

if in any case there's a need to sync an sqlite DB with remote SQL DB, and none of these benefits is needed, what other alternatives are there**?** its easy to manage a service in-between the DBs with php, I did that for Uploading part of syncing process,but for the downloading part I feel silly if I use the query filling method,cause in near future remote db might get large and larger.the only solution that comes to my mind is to write my own sync activity/service, but I dont know how to access the last update date to SQLite db/table (other than specifying a _date in every table,) to check if it is necessary to sync again ? I feel my head is between two places!

like image 785
Shervin Avatar asked Jul 16 '14 13:07

Shervin


2 Answers

You are mixing the problem. 1- Do you really have to use sync Adapter ??? So if yes, you are gonna have a Sync call per table and no needs to save the last call date. Android will do it for you. Just setup your sync timers properly 2- other solution is to do a simple AsyncTask and do your job here. (For exemple if you have to do it only once per week)

For your date problem, the thing is if you really wants to know if you are up to date you got many solutions. On your server save the date, or increment a version and compare these when you call a sync from your device to know if you have to sync or not. An other solution is to simply just refresh your db wherever it is updated or not(for exemple you got a small db, so no need to create an optimized system).

I faced the same problem months ago and hoped this helped you.

like image 169
McflyDroid Avatar answered Nov 12 '22 22:11

McflyDroid


You might want to consider this article:

https://www.bignerdranch.com/blog/choosing-the-right-background-scheduler-in-android/

It makes it clear how syncadapter is a good choice as a result of lesser convenient options when needing to utilize the battery well and go out to the network.

I don't recommend Asyntask for theses reasons: http://blog.danlew.net/2014/06/21/the-hidden-pitfalls-of-asynctask/

If syncadapter is really not working for you there is android's best practices which suggests to use an IntentService and WakefulBroadcastReceiver with partial wake lock when doing long-running operations. It says "the Android framework offers several classes that help you off-load operations onto a separate thread that runs in the background. The most useful of these is IntentService." https://developer.android.com/training/run-background-service/index.html https://developer.android.com/training/scheduling/wakelock.html

there must be some truth to it since they wrote it.

like image 25
Droid Teahouse Avatar answered Nov 13 '22 00:11

Droid Teahouse