Effective in 2026, to align with our trunk stable development model and ensure platform stability for the ecosystem, we will publish source code to AOSP in Q2 and Q4. For building and contributing to AOSP, use android-latest-release. The android-latest-release manifest branch will always reference the most recent release pushed to AOSP. For more information, see Changes to AOSP .
Google 會運用 AI 技術將內容翻譯成你偏好的語言,但可能會出錯。
應用程式相容性預寫記錄
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android 9 推出 SQLiteDatabase 的特殊模式,稱為「相容性預先寫入記錄 (WAL)」,可讓資料庫使用 journal_mode=WAL,同時保留每個資料庫最多一個連線的行為。
除非應用程式符合下列任一條件,否則系統預設會為應用程式的資料庫啟用相容性 WAL:
呼叫 SQLiteDatabase.enableWriteAheadLogging 或 disableWriteAheadLogging ,選擇啟用或停用預先寫入記錄
透過呼叫 SQLiteDatabase.OpenParams.setJournalMode(String mode) 明確要求使用日記模式
啟用 WAL 日誌模式可大幅提升效能,並減少寫入量。舉例來說,在 ext4 檔案系統中,WAL 可將寫入速度提升 4 倍。
相容性 WAL 預設為啟用,不需要任何額外的實作作業。
停用相容性 WAL
如要停用相容性 WAL 模式,請疊加 db_compatibility_wal_supported 設定資源。
例如:
<bool name="db_compatibility_wal_supported">false</bool>
如果 WAL 日誌模式無法提供優於傳統復原日誌模式的效能優勢,您可能需要停用相容性 WAL。舉例來說,在 F2FS 檔案系統上,雖然 SQLite 支援原子寫入,且 DELETE 日誌效能與 WAL 類似,但 WAL 可能會增加 10% 至 15% 的寫入量。
驗證
如要驗證相容性 WAL 模式,請從 CtsDatabaseTestCases 模組執行 CTS 測試 。啟用相容性 WAL 時,CTS 測試會驗證預期行為。
注意: 停用相容性 WAL 模式後,CTS 測試就會通過。
這個頁面中的內容和程式碼範例均受《內容授權 》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2026-10-11 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2026-10-11 (世界標準時間)。"],[],[]]