I'm building a (master-detail) view that has 2 fragments: a ListFragment and a more detailed Fragment view. Clicking on any item in the list reveals a Detail View. For the ListFragment, I'm using a LoaderManager with a CursorLoader, to manage my queries (I've been following the excellent guidelines in Alex Lockwood's posts on the subject).
When it comes to revealing the "detail" view (by clicking on the list view), I need to query the same content provider, and get a single row of information. I'm unsure as to how best to handle this.
Since I'm essentially getting back a single row, and can free the cursor right away:
startManagingCursor manages Cursors, whereas the LoaderManager manages Loader<D> objects. The advantage here is that Loader<D> is generic, where D is the container object that holds the loaded data. In other words, the data source doesn't have to be a Cursor; it could be a List , a JSONArray … anything.
A CursorLoader is a specialized member of Android's loader framework specifically designed to handle cursors. In a typical implementation, a CursorLoader uses a ContentProvider to run a query against a database, then returns the cursor produced from the ContentProvider back to an activity or fragment.
Use the LoaderManager.
The same reason you are creating the Loader in your List view is the same reason you should create it in the Details View. Any heavy operations should be placed on a background thread to prevent UI unresponsiveness. Database interactions are no exception to that rule. It may seem like your data loads instantly but in reality you're doing some heavy work directly on the UI thread which can give unwanted performance in your UI
Project butter, yo
Plus, you get the added benefits of the LoaderManager retaining your results. So, when you rotate and reload the data it is loading a cached result instead of you having to retain all of the data yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With