Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Edit: Updated answer to reflect updated question 1:</p> <blockquote> <p>1) Every time a call is made to fetchTodo a new cursor will be created and returned. Leaving the previous cursor for the garbage collector. So, if I don't use startManagingCursor or even the CursorLoader for that matter, should I call a .close() on the cursor when I'm done with it ?</p> </blockquote> <p>Yes, you should definitely either tell Android to <code>startManagingCursor()</code>, use <code>LoaderManager</code>/<code>CursorLoader</code> or <code>close()</code> it yourself. Not doing so will leak memory, the GC won't help with that as there's native resources behind the <code>Cursor</code> (e.g. file handles to the database).</p> <blockquote> <p>2) Cursor also has a .deactive() method and the documentation says it uses less resources (than active cursors). When exactly should I use this? ...</p> </blockquote> <p><strong>EDIT</strong> to other readers: The OP found an answer and posted it in his question. The following still holds:</p> <p>I've never used <a href="http://developer.android.com/reference/android/database/Cursor.html#deactivate%28%29" rel="noreferrer"><code>deactivate()</code></a> (there's no <code>deactive()</code>), maybe someone else can explain this. If you want really painless requery/updates, do check out the <code>LoaderManager</code> framework -- it's not only for Honeycomb: using the compat library you can use <code>LoaderManager</code> (and <code>Fragments</code>) down to Android 1.6. Not only is it less code for you to write, but it completely offloads these things to Android, much more so than <code>startManagingCursor()</code>.</p> <p><strong>EDIT2: Some notes on <code>LoaderManager</code></strong></p> <p>There are <code>LoaderManager</code> tutorials on developer.android.com but these are quite... complex and hard to understand the first time like most of the tutorials there. I also had to dig a lot, the best all-in-one stop I found so far is <a href="http://mobile.tutsplus.com/tutorials/android/android-sdk_loading-data_cursorloader/" rel="noreferrer">http://mobile.tutsplus.com/tutorials/android/android-sdk_loading-data_cursorloader/</a> (plus all the javadocs and compat lib source you can find) --- the way <code>LoaderManager</code> works is very similar to the (now also deprecated, replaced by <code>DialogFragment</code>) managed dialogs with their <code>onCreateDialog</code>, <code>onPrepareDialog</code> methods where you just tell Android to "show dialog #123" and then Android calls your code with that ID; same for loaders: "load loader #123", Android calls on <code>onCreateLoader()</code>.</p> <p>The only obvious drawback is initially, that <code>LoaderManager</code> relies heavily on the <code>ContentProvider</code> framework and some people seem to really dislike that. Sure, it's additional learning and code, but once you have a <code>ContentProvider</code> for your own data (even if only used privately in your app), all the data-to-view bindng is a breeze with <code>CursorLoader</code>. IMHO, there's little difference between rolling your own "content provider" and actually implementing the <code>ContentProvider</code> -- but this is just my highly controversial opinion :)</p> <blockquote> <p>3) I know that startManagingCursor/stopManagingCursor are deprecated but I'm not targeting Honeycomb (at least for the time being) and I don't want to deal with the new CursorLoader for now. But in the tutorial above, startManagingCursor is used everywhere, but stopManagingCursor is never called once. Why not? Does Android deals with that in it's own way? Any situation I should call stopManagingCursor?</p> </blockquote> <p>Once you call <code>startManagingCursor()</code> the <code>Cursor</code> is no longer your problem. Android will take care of closing the Cursor when your <code>Activity</code> gets destroyed (user navigates away, orientation change, ...). There's no need to match a call to <code>startManagingCursor()</code> with a call to <code>stopManagingCursor()</code> -- you usually don't want to take on the burden of managing a <code>Cursor</code> again once you've gotten rid of it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload