在 Android 中进行交易时,从 API 11 开始有 beginTransaction() 和 beginTransactionNonExclusive() 方法。
对我而言,如果我的应用程序仅针对 API 11 及更高版本的设备,我从文档中不是很清楚我是否应该对我拥有的所有事务使用beginTransactionNonExclusive()在我的申请中。有什么缺点吗?
还提到,如果我理解正确的话,要使 beginTransactionNonExclusive() 正常工作,数据库必须启用预写日志记录。
我试图寻找一些关于此的文章,但我无法从 Google 中找到任何关于此的内容,我找到了 this article看起来不错,但它是日文的。
对于指导何时以及如何使用 beginTransactionNonExclusive() 的任何帮助,我们将不胜感激。
最佳答案
我认为您应该将 beginTransactionNonExclusive 与 enableWriteAheadLogging 一起使用。
根据文档:
It is a good idea to enable write-ahead logging whenever a database will be concurrently accessed and modified by multiple threads at the same time. However, write-ahead logging uses significantly more memory than ordinary journaling because there are multiple connections to the same database. So if a database will only be used by a single thread, or if optimizing concurrency is not very important, then write-ahead logging should be disabled.]
关于安卓 SQLite : Should I use beginTransactionNonExclusive() instead of beginTransaction() for ALL transactions if my app is only for API >= 11?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29224032/