title: Sync service stays awake even though the syncAdapter does nothing
body: <h2>Background</h2>
  
  <p>We've added an account to the app so that it will be shown when the user clicks on a contact's image (as presented <a href="http://www.androidpolice.com/2011/11/20/getting-to-know-android-4-0-part-5-everything-changes-in-contacts-even-the-name/" rel="nofollow">here</a> on the "Contacts Cards" section).</p>
  
  <p>For now, we don't need to have any functionality when syncing, so the code for "onPerformSync" is totally empty. Maybe later we will add code for it.</p>
  
  <h2>The problem</h2>
  
  <p>For some reason, on some devices (like the Nexus 4 , with Android 4.3) , it seems that the Sync service stays awake for a very long time (at least 9 hours, could be more), even though it has nothing to do.</p>
  
  <p>On such devices, the app drains the battery so it's crucial to fix this issue.</p>
  
  <p>However, according to what I've read and heard, the functionality requires that we have a syncAdapter even if it doesn't need to do anything.</p>
  
  <h2>The code</h2>
  
  <p>Actually there is nothing special with the code as it's almost identical with other samples. it even has a lot less code since we don't need syncing at the moment.</p>
  
  <p>I will write it down nevertheless:</p>
  
  <p><strong>SyncAdapter</strong> :</p>
  
  <pre><code>public class SyncAdapter extends AbstractThreadedSyncAdapter {
  
      public SyncAdapter (Context context, boolean autoInitialize) {
          super(context, autoInitialize);
      }
  
      @Override
      public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
              SyncResult syncResult) {
      }
  
  }
  </code></pre>
  
  <p><strong>SyncService</strong> :</p>
  
  <pre><code>public class SyncService extends Service {
  
      private static final Object sSyncAdapterLock = new Object();
      private static SyncAdapter sSyncAdapter = null;
  
      @Override
      public void onCreate() {
          synchronized (sSyncAdapterLock) {
              if (sSyncAdapter == null) {
                  sSyncAdapter = new SyncAdapter (getApplicationContext(), true);
              }
          }
      }
  
      @Override
      public IBinder onBind(final Intent intent) {
          return sSyncAdapter.getSyncAdapterBinder();
      }
  }
  </code></pre>
  
  <p>EDIT: I've decided to show more code in order to try to give more clues to this problem:</p>
  
  <p><strong>manifest</strong>:</p>
  
  <pre><code>&lt;service
      android:name="...SyncService"
      android:exported="true" &gt;
      &lt;intent-filter&gt;
          &lt;action android:name="android.content.SyncAdapter" /&gt;
      &lt;/intent-filter&gt;
  
      &lt;meta-data
          android:name="android.content.SyncAdapter"
          android:resource="@xml/syncadapter" /&gt;
      &lt;meta-data
          android:name="android.provider.CONTACTS_STRUCTURE"
          android:resource="@xml/contacts" /&gt;
  &lt;/service&gt;
  </code></pre>
  
  <p><strong>contacts.xml</strong></p>
  
  <pre><code>&lt;ContactsSource xmlns:android="http://schemas.android.com/apk/res/android" &gt;
  
      &lt;ContactsDataKind
          android:detailColumn="data3"
          android:icon="@drawable/app_icon"
          android:mimeType="vnd.android.cursor.item/....profile"
          android:summaryColumn="data2"/&gt;
  
  &lt;/ContactsSource&gt;
  </code></pre>
  
  <p><strong>syncadapter.xml</strong></p>
  
  <pre><code>&lt;sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
      android:accountType="....contacts"
      android:allowParallelSyncs="false"
      android:contentAuthority="com.android.contacts"
      android:isAlwaysSyncable="false"
      android:supportsUploading="false"
      android:userVisible="false" /&gt;
  </code></pre>
  
  <p><strong>AuthenticatorActivity</strong>:</p>
  
  <pre><code>public class AuthenticatorActivity extends AccountAuthenticatorActivity {
  
      @Override
      public void onCreate(final Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          final Intent res = new Intent();
          res.putExtra(AccountManager.KEY_ACCOUNT_NAME, ...);
          res.putExtra(AccountManager.KEY_ACCOUNT_TYPE, ...);
          res.putExtra(AccountManager.KEY_AUTHTOKEN, ...);
          final Account account = new Account(AccountGeneral.ACCOUNT_NAME, ...);
          final AccountManager accountManager = AccountManager.get(this);
          accountManager.addAccountExplicitly(account, null, null);
          ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, false);
          ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 0);
          setAccountAuthenticatorResult(res.getExtras());
          setResult(RESULT_OK, res);
          finish();
      }
  }
  </code></pre>
  
  <h2>The question</h2>
  
  <p>Why does it occur?</p>
  
  <p>We've followed all steps like on the samples yet the sync service keep staying alive, which (probably) holds the wake lock (as written <a href="http://software.intel.com/en-us/articles/wakelocks-detect-no-sleep-issues-in-android-applications#_Toc358278564" rel="nofollow">here</a>) .</p>
  
  <p>Perhaps I need to call "<a href="http://developer.android.com/reference/android/content/ContentResolver.html#setSyncAutomatically%28android.accounts.Account,%20java.lang.String,%20boolean%29" rel="nofollow">setSyncAutomatically</a>" or "<a href="http://developer.android.com/reference/android/content/ContentResolver.html#setIsSyncable%28android.accounts.Account,%20java.lang.String,%20int%29" rel="nofollow">setIsSyncable</a>" ? If so, does it mean that syncAdapters are automatically set to sync by default? And where should I even call it ? In the "<a href="http://developer.android.com/reference/android/accounts/AbstractAccountAuthenticator.html#confirmCredentials%28android.accounts.AccountAuthenticatorResponse,%20android.accounts.Account,%20android.os.Bundle%29" rel="nofollow">confirmCredentials</a>" function?</p>
  
  <p>Yet it still doesn't explain why the service keep running even though it has nothing to do, and when we will use the SyncAdapter for syncing we will have to deal with this problem again.</p>