DB error while creating CookieSyncManager

If the app has services, or other processes, then you can see this kind of error when using CookieSyncManager.

01-13 16:44:46.674: E/Database(4298): CREATE TABLE android_metadata failed
01-13 16:44:46.690: E/Database(4298): Failed to setLocale() when constructing, closing the database
01-13 16:44:46.690: E/Database(4298): android.database.sqlite.SQLiteException: database is locked
01-13 16:44:46.690: E/Database(4298): at android.database.sqlite.SQLiteDatabase.native_setLocale(Native Method)
01-13 16:44:46.690: E/Database(4298): at android.database.sqlite.SQLiteDatabase.setLocale(SQLiteDatabase.java:2113)
01-13 16:44:46.690: E/Database(4298): at android.database.sqlite.SQLiteDatabase.(SQLiteDatabase.java:1966)
01-13 16:44:46.690: E/Database(4298): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:887)
01-13 16:44:46.690: E/Database(4298): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:965)
01-13 16:44:46.690: E/Database(4298): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:958)
01-13 16:44:46.690: E/Database(4298): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:576)
01-13 16:44:46.690: E/Database(4298): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
01-13 16:44:46.690: E/Database(4298): at android.webkit.WebViewDatabase.getInstance(WebViewDatabase.java:214)
01-13 16:44:46.690: E/Database(4298): at android.webkit.WebSyncManager.(WebSyncManager.java:65)
01-13 16:44:46.690: E/Database(4298): at android.webkit.CookieSyncManager.(CookieSyncManager.java:69)
01-13 16:44:46.690: E/Database(4298): at android.webkit.CookieSyncManager.createInstance(CookieSyncManager.java:96)

This happens because the DB created inside the CookieSyncManager is accessible from only one process.
I couldn’t find the way to use the CookieSyncManager from more than one process.

Also, I tried to CookieSyncManager.createInstance() from one process and CookieSyncManager.getInstance() from another, but it didn’t work.

I should have to solve this problem by only using the CookieSyncManager from one process.
Also keep in mind that CookieManager requires CookieSyncManager to work.

FacebookTwitterGoogle+