Android Kotlin Auto Close Resource/Cursor on Exception

Sep 24, 2019
val contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URIval projections = arrayOf(    MediaStore.Images.Media._ID,    MediaStore.Images.ImageColumns.DATA)contentResolver.query(contentUri, projections, null, null, null)?.use { cursor ->    if (cursor.moveToFirst()) {        val imageUriIndex = imageCursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)    }    do {        val imageUri = imageCursor.getString(imageUriIndex)    } while (cursor.moveToNext())    // cursor.close()}

NOTE: Refer use

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.