Android developers get programming extensions for Kotlin

Posted on 07-02-2018 , by: admin , in , 0 Comments

Having endorsed Kotlin as a language for Android development last year, Google is now previewing beta extensions to improve the Kotlin development experience.

Called Android KTX, the extensions are designed to make writing Kotlin code more concise and idiomatic. An API layer is provided to work on top of Android’s framework and support library. KTX marks the first time Google has released a library specifically for Kotlin developers. KTX, however, is not intended to add new features to Android APIs.

Features in Android KTX

Android’s platform developers say KTX simplifies code in many cases. For example:

  • KTX adds an extension function to the Android String class enabling more-natural conversion of strings to URIs.
  • When editing SharedPreferences, which provides an interface to access and modify preference data, KTX code is shorter and more natural to read and write.
  • Less code also would be needed when translating the difference between two paths in an Android program.

KTX package names begin with androidx, a new prefix to be used in future versions of the support library. KTX proponents hope the division between androidx.* and android.*  will make it more obvious which APIs are bundled with the platform and which are static libraries for developers working with different versions of Android.