开发者

Should the tutorial Notepadv3 close its database?

开发者 https://www.devze.com 2023-02-16 12:19 出处:网络
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,

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消