Search code examples
androideclipseandroid-contentprovider

Using Content Provider Cursor


I have written two apps. One is used to create data and store in a database, the other is used to display information from the first app's database. I need these two to be separate apps. The second app that displays the information has to make multiple calls to the first app's database. It's all working fine and well, but I can't close the database in the first app's content provider. I've read at Closing the database in a ContentProvider that I'm not supposed to which is fine. The problem is as I'm working on the second app, Eclipse's Logcat is just flooded with unclosed database messages. One message per query and I'm making multiple queries at a time.

Finally the question: Is there a way to either setup Eclipse to not display this certain error message, or filter the message out of the logcat?

Thanks TJ


Solution

  • EDIT:

    Make sure you only call:

    getReadableDatabase()
    

    once, as per:

    How to avoid db not close and cursor exception

    Whenever you've finsihed pulling information from a cursor you need to call:

    cursor.close();
    

    So if you have some call:

    public void parseValsFromCursor(Cursor C) {
      String val = c.getString(c.getColumnIndex(MYCOLUMN));
      Log.e(TAG,val);
    
     }
    

    and then you try and do another db query, you'll see this error.

    The fix is to modify the cursor parsing code to include the .close() method like so:

    public void parseValsFromCursor(Cursor C) {
      String val = c.getString(c.getColumnIndex(MYCOLUMN));
      Log.e(TAG,val);
      c.close();
     }