Disabling sqlite Write-Ahead logging in Android Pie

前端 未结 5 650
天涯浪人
天涯浪人 2021-01-04 18:56

In Android Pie sqlite Write-Ahead logging (WAL) has been enabled by default. This is causing errors for my existing code only in Pie devices. I have been unable to turn off

5条回答
  •  北荒
    北荒 (楼主)
    2021-01-04 19:26

    The best and simplest way to disable WAL mode in your Database is as follows:

    public class MyDbHelper extends SQLiteOpenHelper {
    
        //...
    
        @Override
        public void onOpen(SQLiteDatabase db) {
            db.disableWriteAheadLogging();  // Here the solution
            super.onOpen(db);
        }
    
        //...
    }
    

    This way, all access to your database will be with WAL mode disabled. As much as you open and close multiple connections throughout the implementation of your App

提交回复
热议问题