Managing SQLite Connections in Android

前端 未结 2 1064
攒了一身酷
攒了一身酷 2020-12-30 03:25

I have a (hopefully) quick question regarding handling SQLite database connections in Android. I have an app that is composed, naturally, of several activities. I have no tr

相关标签:
2条回答
  • 2020-12-30 04:05

    Connection opening in SQLite is about 0.2ms.

    The best practice tells us to open and close the connection each time we need one.

    0 讨论(0)
  • 2020-12-30 04:13

    Just use SQLiteOpenHelper.getReadableDatabase() and SQLiteOpenHelper.getWriteableDatabase() - Android will manage and cache the connection so you don't need to.

    In fact, refer to the official Google Using Databases documentation:

    To write to and read from the database, call getWritableDatabase() and getReadableDatabase(), respectively. These both return a SQLiteDatabase

    0 讨论(0)
提交回复
热议问题