diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index 189905f29..4b043fa22 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -955,7 +955,9 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { // update directories and media files in the local db, delete invalid items updateDBDirectory(directory) if (!directory.isRecycleBin()) { - mediaDB.insertAll(curMedia) + Thread { + mediaDB.insertAll(curMedia) + }.start() } getCachedMedia(directory.path, getVideosOnly, getImagesOnly) { @@ -1029,10 +1031,13 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { dirs.add(newDir) setupAdapter(dirs) try { - directoryDao.insert(newDir) - if (folder != RECYCLE_BIN) { - mediaDB.insertAll(newMedia) - } + // make sure to create a new thread for these operations, dont just use the common bg thread + Thread { + directoryDao.insert(newDir) + if (folder != RECYCLE_BIN) { + mediaDB.insertAll(newMedia) + } + }.start() } catch (ignored: Exception) { } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt index 8b7bae108..5ac44db95 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt @@ -873,7 +873,9 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { if (!isFromCache) { val mediaToInsert = (mMedia).filter { it is Medium && it.deletedTS == 0L }.map { it as Medium } try { - mediaDB.insertAll(mediaToInsert) + Thread { + mediaDB.insertAll(mediaToInsert) + }.start() } catch (e: Exception) { } }