Image for post
Image for post

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 basics of WorkManager

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 restarts. …


Image for post
Image for post

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.

Define the database table

In our database we have only one table: the one containing words. The Word class represents an entry in the table and it needs to be annotated with @Entity. We use @PrimaryKey to define the primary key for the table. Based on this, Room will generate a SQLite table, with the same name as the class name. Each member of the class becomes a different column in the table. The column name and type is given by the name and type of each field. You can change it by using the @ColumnInfo annotation. …


Image for post
Image for post

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

Conciseness, simplicity and productivity

Kotlin’s conciseness has effects on all stages of development:

  • As an author it means that you can focus on the problem you need to solve, rather than on the syntax. Less code means less to test and less to debug and less chances of creating bugs. …


Image for post
Image for post

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.

If you prefer watching a video to reading a blog post check it out…


Image for post
Image for post

Kotlin Vocabulary: data classes

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 toString(), equals() and 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.

Usage overview

To declare a data class, use the data modifier and specify the properties of the class as val or var parameters in the constructor. As with any function or constructor, you can also provide default arguments, you can directly access and modify properties and define functions inside your class. …


Image for post
Image for post

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.

Q: Should I learn Kotlin for Android?

The questions we get most often are on the same line:

  • “What should I choose to learn between Kotlin and the Java programming language for a beginner?”
  • ​”I’ve done the basics of the Java programming language, is it the right time for me to switch to Kotlin for Android development?”


Image for post
Image for post

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!).

App quality

The quality of your app doesn’t only have an impact on your user experience. There are several other elements that will be affected by a high number of…


Image for post
Image for post

Kotlin Vocabulary — destructuring

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.

Usage

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:

By default, all data classes support destructuring. …


Image for post
Image for post

Kotlin Vocabulary

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.

Basic usage

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:

Java interop

By default, Java doesn’t recognize the default value overload:

To instruct the compiler to generate the overload methods, use the @JvmOverloads annotation on your Kotlin…


Image for post
Image for post

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!

What’s new in Jetpack

New in Alpha

Hilt — Jetpack’s recommended library for Dependency Injection

Hilt is a new Android library which simplifies dependency injection (DI) in your application. Hilt lets you focus on just the important parts of defining and injecting bindings without worrying about managing all of the DI setup and wiring. …

About

Florina Muntenescu

Android Developer Advocate @Google

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store