Early this week, Google released a new version of their support library (22.1). In this article we are going to take a look at one specific library, AppCompat-22.1.1, and see how it brings a better consistent UI accross Android versions.
CursorLoaders are a great way to load data from a content provider in the background while managing correctly the Activity lifecycle. When creating the CursorLoader in the onCreateLoader()
method, you specify a url, projections and selections with their arguments to be executed against the content provider and get result back. Once the query is executed in the background, a Cursor is returned to your activity via the onLoadFinished()
method. This is great but limited to one and only one query against the content provider.
Recently, I’ve decided to replace the ListViews in my application with the new RecyclerView. Using Cursor all over my application, I needed an equivalent of the CursorAdapter
class. I look up the the recycler-view support library hoping I would find something ready to use but unfortunately there wasn’t. I’ve found a couple third-party implementations of a “CursorRecyclerAdapter” and decided to use one.
A few weeks later, I was profiling my applications and noticed I had a memory problem. After using MAT to track down the leak, I realized the third-party class I included in my project was the culprit! Fixing the problem was easy, but I can’t help myself thinking about all the developers looking for a CursorRecyclerAdapter library who found this leaky one and used it in their apps without noticing the problem.