Skip to content Skip to sidebar Skip to footer

How Does One Listen For Progress From Android Syncadapter?

I recall reading about a broadcast receiver interface from the sync adapter or some ResultReceiver of sync progress events. Is there something built into the SyncAdapter pattern o

Solution 1:

I Have just implemented a Broadcast receiver from a sync adapter and it works like clockwork!

Using a Receiver set as an inner class and calling registerReceiver in onCreate and unregisterReceiver in onDestroy did this for me.

As I have one strategy method to spawn and query a number of threads, All I have at the begining of a SyncAdapter run are:

Intentintent=newIntent();
intent.setAction(ACTION);
intent.putExtra(SYNCING_STATUS, RUNNING);
context.sendBroadcast(intent); 

And at the end of the sync run i have:

intent.putExtra(SYNCING_STATUS, STOPPING);
context.sendBroadcast(intent); 

Within my Activity, I declare:

onCreate(Bundle savedInstance){

super.onCreate(savedInstance);
SyncReceiver myReceiver = newSyncReceiver();
RegisterReceiver(myReceiver,ACTION);

}



onDestroy(){

super.onPause();
unRegisterReceiver(myReceiver);

}



 publicclassSyncReceiverextendsBroadcastReceiver {

  @OverridepublicvoidonReceive(Context context, Intent intent) {
            Bundle extras = intent.getExtras();
    if (extras != null) {
        //do something  
    }
   }
 }

For this scenario you do not need to add your receiver to the manifest file. just use as is!

Solution 2:

What works:

The method suggested in a 2010 Google IO session, Developing Android REST client applications is to place columns into your ContentProvider as tags to indicate that a record is being fetched or placed or etc. This allows a per-row spinner (or other visual change) to be placed in your UI. You might do that through a custom CursorAdapter that drives a ListView. Your ContentProvider is on the hook to make the flags change as needed.

What doesn't:

You can also use a SyncStatusObserver -- Which is pretty much useless since it responds to every change of status, not just your specific account/contentauthority pair, and really doesn't tell you much anything at all other than that a change occured. So, you can't tell what is being synced, and you can't distinguish "start of sync event" from "end of sync event". Worthless. :P

Post a Comment for "How Does One Listen For Progress From Android Syncadapter?"