Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5931619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:43:12+00:00 2026-05-22T14:43:12+00:00

I am developing an app in Android that performs a background sync with a

  • 0

I am developing an app in Android that performs a background sync with a server (using SyncAdapter and authentication etc).

When the foreground app (with UI) is started, there maybe a background sync in progress, or optionally it may start one via a UI button.

I would like a way to “plug into” an on-going background sync (whether started by the system, or the periodic sync setting or the UI) and show it’s progress in the foreground activity.

The ContentResolver documentation (http://developer.android.com/reference/android/content/ContentResolver.html) mentions a mysterious “SyncObserver” that has no link to javadoc and is not documented (that I can find).

There are some other pages around that mention it (http://www.chinaup.org/docs/migrating/m5-0.9/changes/android.content.ContentResolver.html) but I can’t find out more about it.

Has anyone implemented this beast?

If not, does anyone have example code or recommendations on tracking the progress of a background sync in a foreground Activity?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:43:13+00:00Added an answer on May 22, 2026 at 2:43 pm

    I had this same problem and ended up implementing it with a combination of 1) a broadcast from the SyncAdapter, and 2) using SharedPreferences to indicate status.

    In the SyncAdapter, something like this this:

    public static final String START_SYNC = "com.whatever.sync.start";
    public static final String STOP_SYNC = "com.whatever.sync.stop";
    public static final String SYNC_PROGRESS = "syncProgress";
    
    
    public void onPerformSync(Account account, Bundle extras, String authority,
        ContentProviderClient provider, SyncResult syncResult) {
    
            // Add an integer to the shared settings to indicate the status
            SharedPreferences settings = mContext.getSharedPreferences(Constants.PREFS, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putInt(SyncAdapter.SYNC_PROGRESS, 0);
            editor.commit();
    
            Intent intent = new Intent();
            intent.setAction(START_SYNC);
            mContext.sendBroadcast(intent);
    
    
            //... do some stuff, setting SYNC_PROGRESS to other values and
            // sending more broadcasts as the state changes
    
            // When we are done, remove the "in progress" setting and store some
            // other data
            editor.putString(SyncAdapter.LAST_UPDATED, new Date().toString());
            editor.remove(SyncAdapter.SYNC_PROGRESS);
            editor.commit();
    
            Intent stopIntent = new Intent();
            stopIntent.setAction(STOP_SYNC);
            mContext.sendBroadcast(stopIntent); 
          }
    

    In the activity we do two things at resume 1) check the shared preference for whether a sync is currently in progress, 2) register to listen for broadcasts with a receiver.

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    // .. do some UI stuff
    
        mReceiver = new SyncReceiver(this);
    }
    
    @Override
    public void onResume() {
        super.onResume();
    
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(SyncAdapter.START_SYNC);
        intentFilter.addAction(SyncAdapter.STOP_SYNC);
        registerReceiver(mReceiver, intentFilter);  
    
        showProgress();
    }
    
    public void showProgress() {
        SharedPreferences settings = getSharedPreferences(Constants.PREFS, 0);
        if (settings.contains(SyncAdapter.SYNC_PROGRESS)) {
            // ... set the UI to show that a sync is in progress
        } else {
            // ... set the UI to show that a sync is NOT in progress
        }
    }
    
    private class SyncReceiver extends BroadcastReceiver {
    
        private MyActivity mActivity;
    
        public SyncReceiver(MyActivity activity) {
            mActivity = activity;
        }
    
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(SyncAdapter.START_SYNC)) {
                Log.i("@string/app_name", "Started sync");
                mActivity.showProgress();
            }
            else if (intent.getAction().equals(SyncAdapter.STOP_SYNC)) {
                Log.i("@string/app_name", "Started sync");
                mActivity.showProgress();
            }
        }
    }
    

    This seems to work for me. I must admit I have a feeling that there are some potential issues with this due to the asynchronous nature of the broadcasts. Any input on improving my approach would be appreciated!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm planning on developing an app for android that requires a back-end server to
I am developing an Android App that gets some data from a web server,
I'm developing an Android APP that connects to Google Calendar using GData API for
I am currently developing an Android app that is using a remote MySQL database
So, I'm developing an Android app that communicates with server via a socket. Now,
I am just getting started developing my first Android app, and one function that
I am developing an Android app that needs to receive specific informations for each
I'm in the middle of developing android app using google map. My question is
I am developing an app for android mobiles that communicates with a json/rest web
I'm developing an iPhone (and later Android) app that has real-time features, i.e. when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.