Shervin
Shervin

Reputation: 233

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!

Upvotes: 15

Views: 2092

Answers (3)

Nicola Gallazzi
Nicola Gallazzi

Reputation: 8705

Android Jetpack includes WorkManager which is a valid alternative to syncadapters. Main features:

  • Schedule a job according to network availablity or device charging status
  • Backward compatiblity up to api 14
  • Ensures task execution, even if the app or device restarts
  • Intended for deferrable tasks (E.g periodically syncing application data with a server)

In alternative, something similar is Android-Job library by Evernote

Upvotes: 0

Droid Teahouse
Droid Teahouse

Reputation: 1013

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.

Upvotes: 1

McflyDroid
McflyDroid

Reputation: 177

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.

Upvotes: 1

Related Questions