WorkManager provides a set of APIs that makes it easy to schedule asynchronous tasks for immediate or deferred execution that are expected to run even if the app is closed or the device restarts. For Kotlin users, WorkManager provides first-class support for coroutines. In this post I’ll show you the basics of WorkManager with coroutines by building on the WorkManager codelab. So let’s get started!
The WorkManager library is the recommended choice for any task that should continue to run, even if the user navigates away from the particular screen, the user puts the application in background or the device…
Room is a wrapper over SQLite and it makes working with databases on Android so much easier and is by far my favorite Jetpack library. In this post I want to tell you how to use and test Room Kotlin APIs and while we do that, I’ll also share how things work under the hood.
We’re going to use the Room with a view codelab as a basis. Here we’re building a list of words that are saved in the database and displayed on the screen. The user can also add words to the list.
In our database we have…
Kotlin is known for its conciseness and this, in practice, translates into higher productivity. Even more, 67% of professional Android developers who use Kotlin say it has increased their productivity. In this blog post, I’ll share a couple of ways Kotlin has increased the productivity of our partners’ engineers and look at the Kotlin features that help with this.
67% of professional Android developers surveyed who use Kotlin say it has increased their productivity
Kotlin’s conciseness has effects on all stages of development:
When using Android Java APIs in Kotlin, you quickly realise that you’re missing out on some of the Kotlin features that make coding so much easier and pleasant. Instead of writing your own wrappers and extension functions for these APIs, take a look at the Jetpack KTX libraries. Currently, more than 20 libraries have a KTX version, creating sweet idiomatic versions of Java APIs, ranging from Android platform APIs to ViewModels, SQLite and even Play Core. In this post we’ll look at some of the APIs available and peek under the hood to see how they were made.
A Puppy has a name, a breed and a whole lot of cuteness. To model a class that holds just data, you should use a
data class. The compiler simplifies your work by auto generating
hashCode() for you and providing destructuring and copy functionality out of the box letting you focus on the data you need to represent. Read on to learn more about other advantages of data classes, their restrictions and to take a look under the hood of how they’re implemented.
To declare a data class, use the data modifier and specify the properties of…
Ever since we announced our Kotlin support in 2017 we’ve been getting a lot of questions about Kotlin on Android: you wanted to know whether it’s time to learn it, to introduce it to your app, what the best course or tutorial to learn Kotlin is, whether Google is using Kotlin internally and what our plans for the Java programming language are. In this post, I want to answer some of these questions.
The questions we get most often are on the same line:
Users expect to have a seamless experience with your app. Crashes can lead to an increase in poor reviews, uninstalls and even damaging your brand perception. From talking to the community we know that one of the main reasons to adopt Kotlin is safer code. In this post I’ll share a couple of the ways Kotlin improved the stability of a few of our partners’ code but we’ll also look at the results of some Google Play store stats and see if there’s a correlation between using Kotlin and the number of crashes (spoilers: there is!).
The quality of your…
Sometimes you just want to break down one object that contains multiple fields to initialize several separate variables. To achieve this, you can use Kotlin’s destructuring declarations. Read on to find out how to use this feature, what Kotlin types offer it by default, how to implement it in your own classes or for classes that you don’t control but you think would benefit from destructuring and how everything works under the hood.
Destructuring declarations allows us to define local values/variables as such:
It’s a convenient way to work with data coming from functions or collections:
Short and easy to use, default arguments allow you to implement function overloads without the boilerplate. Like many Kotlin features, this can feel like magic. Are you curious to learn its secrets? Read on to find out how default arguments work under the hood.
If you need to overload a function, instead of implementing the same function multiple times, you can use default arguments:
Default arguments can be applied to constructors as well:
By default, Java doesn’t recognize the default value overload:
To instruct the compiler to generate the overload methods, use the
Android Jetpack is a suite of libraries aimed at helping you write high-quality apps easily, supporting older versions of the Android OS. Now, two years after the launch of Jetpack, we’ve seen tremendous adoption by apps, from large developer teams to those just getting started. And that’s just the beginning: today, we’re launching new libraries, along with major updates to existing ones, that we’ve been working on over the past year. Here’s a round up of the latest updates in Jetpack — an extended version of our What’s new in Jetpack talk!
Android Developer Advocate @Google