Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To use LoaderManager for detail view or not?

Tags:

android

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:

  • Should I just use a straight getContentResolver().query() and work with a cursor directly?
  • Use another LoaderManager to manage the cursor and results?
like image 738
RoyM Avatar asked Jan 29 '13 19:01

RoyM


People also ask

What does the startManagingCursor () function do?

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.

What is a cursor loader?

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.


1 Answers

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.

like image 106
dymmeh Avatar answered Oct 04 '22 22:10

dymmeh