I'm using android.arch.work:work-runtime-ktx:1.0.1-rc1
and receiving many SQLiteException which I cannot reproduce.
The exception:
android.database.sqlite.SQLiteException:
at android.database.sqlite.SQLiteConnection.nativeOpen (Native Method)
at android.database.sqlite.SQLiteConnection.open (SQLiteConnection.java:209)
at android.database.sqlite.SQLiteConnection.open (SQLiteConnection.java:193)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked (SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.open (SQLiteConnectionPool.java:185)
at android.database.sqlite.SQLiteConnectionPool.open (SQLiteConnectionPool.java:177)
at android.database.sqlite.SQLiteDatabase.openInner (SQLiteDatabase.java:808)
at android.database.sqlite.SQLiteDatabase.open (SQLiteDatabase.java:793)
at android.database.sqlite.SQLiteDatabase.openDatabase (SQLiteDatabase.java:696)
at android.app.ContextImpl.openOrCreateDatabase (ContextImpl.java:652)
at android.content.ContextWrapper.openOrCreateDatabase (ContextWrapper.java:289)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked (SQLiteOpenHelper.java:223)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase (SQLiteOpenHelper.java:163)
at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase (FrameworkSQLiteOpenHelper.java:92)
at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase (FrameworkSQLiteOpenHelper.java:53)
at androidx.room.RoomDatabase.endTransaction (RoomDatabase.java:340)
at androidx.work.impl.utils.ForceStopRunnable.run (ForceStopRunnable.java:107)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:607)
at java.lang.Thread.run (Thread.java:761)
Scheduling workers like that:
inline fun <reified T : Worker> schedule(interval: Long,
units: TimeUnit,
tag: String,
networkConstraint: NetworkType? = null) {
WorkManager.getInstance().apply {
if (getWorkInfosByTag(tag).get()
.all { it.state == WorkInfo.State.CANCELLED || it.state == WorkInfo.State.FAILED }) {
// Cancel job by tag if the job already scheduled
cancelAllWorkByTag(tag)
// Create job and set tag
val job = PeriodicWorkRequestBuilder<T>(interval, units).addTag(tag)
// Set constraint if networkConstraint != null
networkConstraint?.let {
val constraints = Constraints.Builder()
.setRequiredNetworkType(networkConstraint)
.build()
job.setConstraints(constraints)
}
// Enqueue periodic job if no previous job with same tag is scheduled.
enqueueUniquePeriodicWork(
tag,
ExistingPeriodicWorkPolicy.KEEP,
job.build())
}
}
}
If it is important, the scheduling of one of the workers is performed once in Application#onCreate()
and another worker is scheduled later on after user interactions.
The workers themselves look like this:
internal class SiloWorker(context: Context, params: WorkerParameters)
: Worker(context, params) {
override fun doWork(): Result {
if (isAppInBackground)
return Result.success()
doIntenseDatabaseAndNetworkIOOperations()
return Result.success()
}
}
and are scheduled to run every 15 minutes.
Another strange thing is that I receive these exceptions only on "Android Vitals" tab of Google Play Console, but I found none of them in Firebase crashlytics.
I don't know whether these SQLiteExceptions occur in foreground or in background and there are many devices with different Android versions that are affected by this exception.
What are possible reasons of this behaviour and how can I fix it?
We made a lot of improvements around this area in 2.1.0-alpha03
. Try giving that version a go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With