is it ok to create ORMLite database helper in Application class?

后端 未结 1 693
眼角桃花
眼角桃花 2021-02-07 10:10

I am trying to create an android application using ORMLite package. I have a few activities and services and also use https://github.com/tomquist/Android-Error-Reporter to be ab

相关标签:
1条回答
  • 2021-02-07 10:28

    The overall mechanism looks fine @Alex but as far as I know, onTerminate() is only used in emulated environments so doesn't have much use. You program gets killed by the Android OS when it terminates on a real device so there is no reason to be worried about memory leaks and the such.

    What is most important with your code is that it guarantees a single databaseHelper instance. Each instance has it's own connection to the database and problems happen when there are more than one (1) connection opened to the database in a program. Sqlite handles multiple threads using the same connection at the same time but it doesn't handle multiple connections well and data inconsistencies may occur.

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