BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Kotlin on Android: Android KTX, Kotlin Bootcamp Udacity and More

Kotlin on Android: Android KTX, Kotlin Bootcamp Udacity and More

Leia em Português

This item in japanese

Bookmarks

Google recently presented a series of efforts to improve the Kotlin developer experience on the Android platform, including Android KTX, a Kotlin Bootcamp Udacity course, Lint support in Android Studio 3.2, and more.

According to Stephanie Cuthbertson, product management director at Google, the developer community has embraced the language since Google announced support for Kotlin last year, with 95% of developers saying they are very happy using Kotlin for their Android development. The number of Play Store apps using Kotlin has grown six times since then.

Kotlin is officially supported for building Android apps, fully interoperates with the Java programming language and libraries, and is included with IntelliJ and Android Studio. Kotlin offers a strong type system, type inference, null safety, properties, lambdas extensions, coroutines, higher-order functions, etc.

The Kotlin Bootcamp Udacity course is a free, self-paced, online course aiming to teach the basics of Kotlin. This introduction to Kotlin was created by Google experts in collaboration with Udacity, and is meant for people who already have some experience programming.

The Kotlin Bootcamp Udacity course begins with the foundations of the language from simple statements, to calling functions and declaring classes, while the second part delves into more advanced topics such as collections, constants, how to write extensions, implementing generics, applying annotations, lambdas, high-order functions, etc.

Lint support has been improved on Android Studio 3.2, including many new features. New lint checks have been added to make sure that your Java code interoperates well with your Kotlin code. These checks include looking for the presence of Nullability annotations, placing lambda parameters last, etc. The following settings must to be added to your build.gradle to enable it:


android {
    lintOptions {
        check 'Interoperability'
    }
}

Android KTX is a set of Kotlin extensions available as part of Jetpack. It optimizes Jetpack and Android platform APIs for Kotlin use. Android KTX aims to make Android development with Kotlin more concise, pleasant and idiomatic. It lets you transform Kotlin code like this:


view.viewTreeObserver.addOnPreDrawListener(
  object : ViewTreeObserver.OnPreDrawListener {
    override fun onPreDraw(): Boolean {
      viewTreeObserver.removeOnPreDrawListener(this)
      actionToBeTriggered()
      return true
    }
});

Into more concise Kotlin code like the following:


view.doOnPreDraw { actionToBeTriggered() }

On a final note, Android Runtime (ART) has been tuned in Android P, so that apps built with Kotlin can run faster. Google has rolled out Kotlin code snippets in the official documentation and an API reference documentation has been published.

Rate this Article

Adoption
Style

BT