SyncAdapter change in Jelly Bean

Recently, when trying one of my apps that uses a SyncAdapter out on the new Jelly Bean emulator, I got the following exception:

java.lang.IllegalStateException: Already released
at android.content.ContentProviderClient.release(ContentProviderClient.java:242)
at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:263)

I apparently made the error of releasing the ContentProviderClient passed in onPerformSync() by calling provider.release();.at the end. While this would seem to me to be good practice, and Android didn’t complain up to Jelly Bean, this now throws an exception and causes havoc with random background crashes.

So to sum up: Don’t release() the ContentProviderClient when your SyncAdapter has finished

About the author

Jesper Borgstrup Jesper is a Masters student of computer science at the University of Copenhagen with many years of experience in writing applications for Android.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>