From 1c2812db481ab72aee5e1194ba6eff5c9edc39fb Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 25 Oct 2018 17:43:41 +0200 Subject: [PATCH] use a singleton single threaded executor for handling Room db queries --- .../simplemobiletools/gallery/databases/GalleryDatabase.kt | 4 +++- .../com/simplemobiletools/gallery/objects/MyExecutor.kt | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/objects/MyExecutor.kt diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/databases/GalleryDatabase.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/databases/GalleryDatabase.kt index 0c94fb848..104a250cf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/databases/GalleryDatabase.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/databases/GalleryDatabase.kt @@ -1,9 +1,10 @@ package com.simplemobiletools.gallery.databases +import android.content.Context import androidx.room.Database import androidx.room.Room import androidx.room.RoomDatabase -import android.content.Context +import com.simplemobiletools.gallery.objects.MyExecutor import com.simplemobiletools.gallery.interfaces.DirectoryDao import com.simplemobiletools.gallery.interfaces.MediumDao import com.simplemobiletools.gallery.models.Directory @@ -25,6 +26,7 @@ abstract class GalleryDatabase : RoomDatabase() { if (db == null) { db = Room.databaseBuilder(context.applicationContext, GalleryDatabase::class.java, "gallery.db") .fallbackToDestructiveMigration() + .setQueryExecutor(MyExecutor.myExecutor) .build() db!!.openHelper.setWriteAheadLoggingEnabled(true) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/objects/MyExecutor.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/objects/MyExecutor.kt new file mode 100644 index 000000000..c4ff990a9 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/objects/MyExecutor.kt @@ -0,0 +1,7 @@ +package com.simplemobiletools.gallery.objects + +import java.util.concurrent.Executors + +object MyExecutor { + val myExecutor = Executors.newSingleThreadExecutor() +}