Android’s Notepad tutorial Notepadv3 opens its database but never exp开发者_如何学Golicitly closes it. To make it correct, should Notepadv3 close its database, presumably with mDbHelper.close();
and, if so, where should that line of code appear?
Updated with a related question: The close method of NotesDbAdapter in the tutorial is implemented via mDbHelper.close()
. Would it be equally effective to implement the close method via mDb.close()
? In other words, is the close method of SQLiteDatabase equivalent to the close method of SQLiteOpenHelper and, if not, why is one preferred over the other?
Yes, you should close the adapter and cursors once you don't need them anymore (for instance, when you finish your activity). That should be executed on the onDestroy
method.
精彩评论