how should I open and close my database properly

前端 未结 5 1654
挽巷
挽巷 2021-02-06 06:39

I have an app which stores some data in a SQLite DB.Also I\'m doing a lot of query an requery in my app.I have about 15 activities in it.And almoust all use the DB to query for

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-06 07:22

    Something you might try is use a singleton that each activity would attach to in its onResume() callback, and detach from in its onPause() callback. When the detach count reaches zero, set a timer which would get canceled in the attach method. If the timer expires, close the database.

提交回复
热议问题