Cómo cerrar correctamente el cursor en Kotlin después de su uso. Sé cómo hacerlo en Java, pero no importa lo que haga en Kotlin, todavía me da una advertencia para cerrarlo.
Lo intenté:
val cursor = context!!.getContentResolver().query(DbProvider.CONTENT_URI_VERSES, null, where, null, null)!! if (cursor.moveToFirst()) { try { arabicTextTV.text = cursor.getString(cursor.getColumnIndex(DbHelper.COL_ARABIC1)) } finally { cursor.close() } }y la forma moderna:
val cursor = context!!.getContentResolver().query(DbProvider.CONTENT_URI_VERSES, null, where, null, null)!! if (cursor.moveToFirst()) { cursor.use { arabicTextTV.text = cursor.getString(cursor.getColumnIndex(DbHelper.COL_ARABIC1)) } }context?.contentResolver?.query(DbProvider.CONTENT_URI_VERSES, null, where, null, null)?.use { if (it.moveToFirst()) { arabicTextTV.text = it.getString(it.getColumnIndex(DbHelper.COL_ARABIC1)) } }https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/use.html