jjzjj

安卓 SQLite : Should I use beginTransactionNonExclusive() instead of beginTransaction() for ALL transactions if my app is only for API >= 11?

coder 2023-12-23 原文

在 Android 中进行交易时,从 API 11 开始有 beginTransaction()beginTransactionNonExclusive() 方法。

对我而言,如果我的应用程序仅针对 API 11 及更高版本的设备,我从文档中不是很清楚我是否应该对我拥有的所有事务使用beginTransactionNonExclusive()在我的申请中。有什么缺点吗?

还提到,如果我理解正确的话,要使 beginTransactionNonExclusive() 正常工作,数据库必须启用预写日志记录。

我试图寻找一些关于此的文章,但我无法从 Google 中找到任何关于此的内容,我找到了 this article看起来不错,但它是日文的。

对于指导何时以及如何使用 beginTransactionNonExclusive() 的任何帮助,我们将不胜感激。

最佳答案

我认为您应该将 beginTransactionNonExclusiveenableWriteAheadLogging 一起使用。

根据文档:

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.]

http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#enableWriteAheadLogging()

关于安卓 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/

有关安卓 SQLite : Should I use beginTransactionNonExclusive() instead of beginTransaction() for ALL transactions if my app is only for API >= 11?的更多相关文章

随机推荐