question of: "If I come back to this code in 6 months, will I understand it in 30 seconds or less and will I feel confident to make a change?" ~ Donn Felker
• androidx.lifecycle:lifecycle-reactivestreams-ktx:$version • androidx.navigation:navigation-runtime-ktx:$version • androidx.navigation:navigation-fragment-ktx:$version • androidx.navigation:navigation-ui-ktx:$version • androidx.work:work-runtime-ktx:$version • com.google.android.play:core-ktx:$version Pick the one that you want!
87)) bundle.putBoolean("KEY_BOOLEAN", false) bundle.putStringArrayList("KEY_STRING_ARRAY", arrayListOf("test1", "test2")) bundleOf("KEY_INT" to 21, "KEY_NAME" to "PRANAY", "KEY_INT_ARRAY" to intArrayOf(8, 87), "KEY_BOOLEAN" to false, "KEY_STRING_ARRAY" to arrayListOf("test1", "test2") ) Create Bundle using KTX
val result = LinkedHashSet<T>(mapCapacity( elements.collectionSizeOrNull()?.let { this.size + it } ?: this.size * 2)) result.addAll(this) result.addAll(elements) return result } Plus operator KTX code
private val uiScope = CoroutineScope(Dispatchers.Main + viewModelJob) override fun onCleared() { super.onCleared() viewModelJob.cancel() } fun fetchData() { uiScope.launch { getUserDataFromAPI() } } private suspend fun getUserDataFromAPI() = withContext(Dispatchers.Default) { // call api } } View Model Use case
object from String val fileFromUri = uri.toFile() // File object from Uri object val uriFromFile = fileFromUri.toUri() // Uri object from File object Uri using KTX