How to refresh Android ListView after SyncAdapter completes a Sync
<p>I have extended an AbstractThreadedSyncAdapter and got it to automatically sync data with my server every x minutes or when I manually request a sync via code. It works perfectly.</p>

<p>So now the next step is automatically updating a ListView containing messages and another containing assigned jobs.</p>

<p>The samples I've found all assume you're changing your dataset from within the same Activity or you otherwise have access to the database cursor the ListView is bound to. Unfortunately for the Android Sync Adapter, this is not the case. It runs in the background and has no reference to anything useful as far as I can tell.</p>

<p>My SyncAdapter:</p>

<pre><code>public class VttSyncAdapter extends AbstractThreadedSyncAdapter {
    private final AccountManager mAccountManager;

    public VttSyncAdapter(Context context, boolean autoInitialize) {
        super(context, autoInitialize);
        mAccountManager = AccountManager.get(context);
    }

    @Override
    public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
        Log.d("Vtt", "onPerformSync for account[" + account.name + "]");
        try 
        {         
            //GET SOME DATA FROM WEBSERVICE AND INSERT INTO SQLITE DB
        } catch (IOException e) {
            e.printStackTrace();
        }

        //WHAT WOULD ONE DO HERE TO ALERT THE LISTVIEW THAT IT SHOULD REFRESH?

        } catch (Exception e) {
            e.printStackTrace();

    }

    public String getsharedresourcestring(String key)
    {
        Context context = getContext();
        SharedPreferences sharedPref = context.getSharedPreferences(context.getString(R.string.preference_file_key), MODE_PRIVATE);
        return sharedPref.getString(key,null);
    }

}
</code></pre>

<p>My Schedule fragment code:</p>

<pre><code>public class ScheduleFragment extends Fragment {
    private ListView listView;
    private List&lt;DeliveryScheduleEntryModel&gt; schedules;


    public ScheduleFragment() {
        // Required empty public constructor
    }

    public static ScheduleFragment newInstance(String param1, String param2) {
        ScheduleFragment fragment = new ScheduleFragment();
        Bundle args = new Bundle();
        //args.putString(ARG_PARAM1, param1);
        //args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            //mParam1 = getArguments().getString(ARG_PARAM1);
            //mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View ret = inflater.inflate(R.layout.fragment_schedule, container, false);

        listView = (ListView) ret.findViewById(R.id.listViewSchedule);

        //GET OUR DATA
        Activity activity = this.getActivity();
        ContentResolver contentResolver = activity.getContentResolver();
        schedules = getSchedule(contentResolver);

        DeliveryScheduleEntryModelList customList = new DeliveryScheduleEntryModelList(activity, schedules);

        listView.setAdapter(customList);
        return ret;
    }

    public List&lt;DeliveryScheduleEntryModel&gt; getSchedule(ContentResolver cr)
    {
        Context context = getContext();
        VttDataSource db = new VttDataSource(context);
        db.open();
        List&lt;DeliveryScheduleEntryModel&gt; ret = db.getAllDeliveryScheduleEntryModel();
        db.close();

        return ret;
    }
}
</code></pre>