From 542072c2387c770e4893a48f8ff7530f3b7ec266 Mon Sep 17 00:00:00 2001 From: Nacho Date: Sat, 18 Jan 2025 01:05:45 +0100 Subject: [PATCH] Forgot to close DB before importing process This will clear the database lock file before closing the application, ensuring that during the second startup the application does not see anything weird with the data. Not closing the database before import can lead to weird behavior. --- .../screens/settingsScreen/NewSettingsScreenControllerImpl.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/screens/settingsScreen/NewSettingsScreenControllerImpl.kt b/app/src/main/java/com/github/nacabaro/vbhelper/screens/settingsScreen/NewSettingsScreenControllerImpl.kt index 53e8515..dc03802 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/screens/settingsScreen/NewSettingsScreenControllerImpl.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/settingsScreen/NewSettingsScreenControllerImpl.kt @@ -91,6 +91,8 @@ class NewSettingsScreenControllerImpl( private fun importDatabase(roomDbName: String, sourceUri: Uri) { context.lifecycleScope.launch(Dispatchers.IO) { try { + var application = context.applicationContext as VBHelper + if (!getFileNameFromUri(sourceUri)!!.endsWith(".vbhelper")) { context.runOnUiThread { Toast.makeText(context, "Invalid file format", Toast.LENGTH_SHORT).show() @@ -98,6 +100,8 @@ class NewSettingsScreenControllerImpl( return@launch } + application.container.db.close() + val dbPath = context.getDatabasePath(roomDbName) val shmFile = File(dbPath.parent, "$roomDbName-shm") val walFile = File(dbPath.parent, "$roomDbName-wal")