Search code examples
androidadapterandroid-adapterandroid-syncadapter

Using AbstractThreadedSyncAdapter before api 11


How do I use AbstractThreadedSyncAdapter for minSDK lower than API-11? The following constructor is complaining about needing API-11.

public DogSyncAdapter(Context context, boolean autoInitialize, boolean allowParallelSyncs) {
    super(context, autoInitialize, allowParallelSyncs);
  }

Solution

  • As it says in the documentation:

    Api level 5:

    public AbstractThreadedSyncAdapter (Context context, boolean autoInitialize)
    

    Api level 11:

    public AbstractThreadedSyncAdapter (Context context, boolean autoInitialize, boolean allowParallelSyncs)
    

    So you just need to implement both constructors, and then call one or other:

    if (sSyncAdapter == null) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                        sSyncAdapter = new NotificationsSyncAdapter(getApplicationContext(), true, true);
                    } else {
                        sSyncAdapter = new NotificationsSyncAdapter(getApplicationContext(), true);
                    }
                }