SyncAdapters.requestSync and Android SyncManager -
i'm trying understand workings of syncadapters. looked @ code when receive gcm notification broadcast receiver. want force syncadapter sync calling requestsync gcm telling app there new data available fetch.
i got code below link: https://software.intel.com/en-us/articles/handling-offline-capability-and-data-sync-in-an-android-app-part-2
public class gcmbroadcastreceiver extends broadcastreceiver { private static final string tag = gcmbroadcastreceiver.class.getsimplename(); public gcmbroadcastreceiver() { } @override public void onreceive(context context, intent intent) { googlecloudmessaging gcm = googlecloudmessaging.getinstance(context); if (googlecloudmessaging.message_type_message.equals(gcm.getmessagetype(intent)) && intent.getextras().containskey("com.example.restaurant.sync_req")) { log.d(tag, "gcm sync notification! requesting db sync server dbversion " + intent.getstringextra("dbversion")); contentresolver.requestsync(new account("dummyaccount", "com.example.restaurant"), restaurantcontentprovider.authority, bundle.empty); } } }
now read syncadapters here: http://naked-code.blogspot.com/2011/05/revenge-of-syncadapter-synchronizing.html) , mentioned that:
a syncadapter service started sync manager, in turn maintains queue of syncadapters.
if phone has couple of different syncadapters related different apps (facebook, twitter etc.) , have items need sync (for example, new posts on facebook or twitter), looks these syncadapters put queue waiting till syncmanager gives go-ahead sync these syncadapters.
if app calls command sync - contentresolver.requestsync(), mean other apps (facebook, twitter etc) gets sync-ed @ same time?
i looked @ definition of requestsync method:
http://developer.android.com/reference/android/content/contentresolver.html#requestsync(android.accounts.account, java.lang.string, android.os.bundle)
public static void requestsync (account account, string authority, bundle extras)
start asynchronous sync operation. if want monitor progress of sync may register syncobserver.
public static void requestsync (syncrequest request)
register sync syncmanager. these requests built using syncrequest.builder.
is requestsync calling syncmanager sync syncadapters?
if use code explicitly force syncadapter run, accounts sync.
bundle bundle = new bundle(); bundle.putboolean(contentresolver.sync_extras_expedited, true); bundle.putboolean(contentresolver.sync_extras_force, true); bundle.putboolean(contentresolver.sync_extras_manual, true); contentresolver.requestsync(null, mycontentprovider.getauthority(), bundle);
syncadapters made sync automatically not immediately. in other words, hard estimate exact time when sync adapter run unless force to. see developer docs on this
Comments
Post a Comment