KAndroid Kotlin extensions for Android, and what replaces them today

KAndroid is a small Apache-2.0 library by Paweł Gajda. It adds Kotlin extension functions for repetitive Android code: text watchers, toasts, intents, threading and logging. It doesn’t add new features. Each helper is a thin wrapper over the platform API it replaces.
KAndroid is served from JitPack. Add the repository, then the dependency:
// settings.gradle (or the allprojects block in an older root build.gradle)dependencyResolutionManagement { repositories { google() mavenCentral() maven { url "https://jitpack.io" } }}dependencies { implementation 'com.github.pawegio:KAndroid:0.8.8@aar'}# gradle.properties: needed because KAndroid uses the Support Libraryandroid.enableJetifier=trueAll the functions live in the com.pawegio.kandroid package.
Examples
Section titled “Examples”All of these examples come from the project’s README.
Finding views
Section titled “Finding views”val textView = find<TextView>(R.id.textView)This is just findViewById with a reified type. Since API 26 the platform’s findViewById<TextView>(R.id.textView) does the same thing, which is why KAndroid deprecated it.
Listeners
Section titled “Listeners”KAndroid has no click-listener helper; Kotlin’s SAM conversion already makes button.setOnClickListener { ... } short. It does wrap the listener interfaces that have several callbacks:
editText.textWatcher { afterTextChanged { text -> preview.text = text }}
searchView.onQueryChange { query -> update(query) }
seekBar.onProgressChanged { progress, fromUser -> if (fromUser) mediaPlayer.seekTo(progress)}Toasts and intents
Section titled “Toasts and intents”toast("Hi, I'm a short toast")longToast(R.string.my_string)
startActivity<SampleActivity>()startActivityForResult<SampleActivity>(REQUEST_CODE)Threading
Section titled “Threading”runAsync starts a new Thread, and runOnUiThread posts to the main looper:
fun fetchDataAndUpdateTextView(textView: TextView, url: String) { runAsync { val data = URL(url).readText() runOnUiThread { textView.text = data } }}That’s one raw thread per call, with no cancellation. If the activity is destroyed while the request is in flight, the callback still touches the old view.
Logging
Section titled “Logging”The log functions are extensions on Any and use the caller’s class name as the tag:
w("Warn log message")e("Error log message")d { "Debug log message" }v("CustomTag", "Verbose log message with custom tag")The lambda forms (d { }, v { }, i { }) only build the message if Log.isLoggable(tag, level) returns true. By default only INFO and above pass that check, so d { } prints nothing unless you raise the level with adb shell setprop log.tag.<ClassName> DEBUG. The string overloads always log.
Modern replacements
Section titled “Modern replacements”| KAndroid | Replacement |
|---|---|
find<T>(id) | View Binding, or findViewById<T>(id) |
textWatcher { afterTextChanged { } } | doAfterTextChanged { } from androidx.core:core-ktx |
runAsync / runOnUiThread | lifecycleScope.launch { withContext(Dispatchers.IO) { ... } } |
startActivity<T>() | startActivity(Intent(this, T::class.java)) |
startActivityForResult<T>(code) | registerForActivityResult(...) (Activity Result API) |
d { } / w() | android.util.Log, or Timber |
© 2026 David Li · Home · Blog · RSS ·Classic site · Built with Astro, Starlight and three.js · Logos:Font Awesome Free (CC BY 4.0)