Home · Android & Kotlin Tutorials

Android Interview Questions and Answers

In this tutorial, you’ll learn Android-specific interview questions and answers.

5/5 3 Ratings

Version

  • Kotlin 1.3, Android 10.0, Android Studio 4.0

Android is one of the most robust mobile operating systems out there. When you interview for a job as an Android Developer, the number of things you need to know may feel overwhelming. The purpose of this article is to guide you through the most common interview questions and answers. You’ll also find links to resources where you can learn more about each topic.

If you’re a candidate preparing for an interview, this tutorial is for you. By studying these questions, and using the links to dive into topics you’re less familiar with, you can look forward to a brilliant interview! And if you’re a recruiter, you’ll also find these questions helpful as you plan your next candidate interview.

Getting Started

Unlike most of the tutorials on this site, this one doesn’t have a project to download. This tutorial is all about theory, with code snippets to illustrate the concepts. The purpose is to prepare you for a comfortable and successful interview!

Note: you can follow this article in any order you want. You can read it from top to bottom, or you can go to a specific section to fill in the gaps.

Now let’s get started!

Android robot with Ray Wenderlich flag

Android

The first questions are specific to the Android platform.

Android robot reading a book

What Is the Android Manifest?

The Android Manifest is an XML file that must be present in every Android app. It provides information about the app to surrounding systems. These include Android build tools, the Android OS and the Google Play Store.

The Manifest includes many types of information. The main ones are:

  1. Package name
  2. Components of the app, such as activities, fragments and services
  3. Permissions needed from the user

For more details, you can review the App Manifest Overview. This article is in the Android developers website.

What Is the Gradle Build System?

Android Studio uses Gradle for building apps. An Android plugin for Gradle compiles, builds and packages apps or libraries. Gradle files also include dependencies and their versions.

Gradle files, historically, use Groovy as their required language. However, since 2019, you can also use the Kotlin language to code Gradle files in Kotlin apps.

We have two great articles on Gradle. Take a look at both Gradle Tutorial for Android: Getting Started and Gradle Tips and Tricks for Android for a deeper dive.

What Are Activities and Fragments?

An activity is a single thing the user can do within your app. The activity class takes care of creating a window in which you place your UI. A fragment is a small piece of functionality within this activity.

Since 2018, Android recommends creating single-activity apps. An app should consist of fragments within a host activity

What Is the App Lifecycle?

For any Android interview, you should be able to explain the lifecycle of an app. When interviewers ask this question, they’re usually looking for familiarity with the activity’s six callbacks:

  • onCreate()
  • onStart()
  • onResume()
  • onPause()
  • onStop()
  • onDestroy()

You should be able to name each activity and describe what it does and why it’s important. If you’re not sure about these, you can review the article Understand the Activity Lifecycle, in the Android developers website.

What are Configuration Changes and When Do They Happen?

Configuration changes cause Android to restart the activity. They include changes to screen orientation, keyboard availability and multi-window mode. When a configuration change occurs, you must issue a call to onDestroy(). You follow this with a call to onCreate().

This is a key design topic! You’ll want to mention ways to support configuration changes and persist data so you can rebuild your activity. One approach might be to use ViewModels, which you’ll cover later.

Design

As you’re thinking about your new app, you must give careful attention to your UI design. Android provides guidelines on both material design and quality design. These will help you build apps that meets users’ expectations for visual coherence and navigability.

What Is Material Design?

Material design is a design language that Google developed in 2014. It consists of the building blocks for your UI components. This language, and the design principles it embodies, are applicable to Android as well as other applications.

Google provides a detailed guide to material design in its Design guidance and code. You can review this guide while developing your apps.

We also have an introductory tutorial on this subject, An Introduction to Material Design with Kotlin. Check it out!

What Are Quality Guidelines?

Google also provides an extensive list of quality guidelines. You can use this list to ensure that your app adheres to current quality standards. If your app passes these tests, you can be sure it meets your users’ expectations for performance, stability, and security.

You can review the Android Quality Guidelines in the Quality guidelines page of the Android developers website.

How Do You Manage Resources for Different Screen Sizes?

Android devices come in a variety of sizes and resolutions. When you’re building your app, it’s important to decide which of the many models you will support. Once you’ve made this decision, there are three common approaches you can take to make sure your app supports all screen sizes:

  1. Use view dimensions.
  2. Create several layouts, depending on the screen.
  3. Provide your images and resources as bitmaps.

Of course, you may also use a combination of these approaches in your app.

The Android developers website covers this in detail in the article Support different screen sizes.

What Are Layouts in Android?

Layouts define the structure of the UI of an app. They consist of View and ViewGroup objects, arranged hierarchically. There are different types of layout:

  1. Constraint Layout
  2. Linear Layout
  3. Relative Layout

Because this is one of the most complex concepts in Android, we cover layouts in both a video course, Beginning Android Layouts, and a tutorial, ConstraintLayout Tutorial for Android: Getting Started. Please review them if you need a better understanding of this important subject!

What Is a RecyclerView?

Most apps out there contain at least one RecyclerView, so it’s a key topic you should know. A RecyclerView is a widget provided in the Android SDK. It’s used to display a list of elements. RecyclerView is designed to display lists that don’t fit on one screen and require scrolling.

What is RecyclerView Adapter?

The RecyclerView Adapter tells the RecyclerView what to display in each ViewHolder.

What Kind of Layouts Can You Have for RecyclerViews?

When you create a RecyclerView, you have the flexibility to define one of the following layout types.

  1. Linear Layout
  2. Grid Layout

There’s a lot the developer needs to know about RecyclerView. If you need a refresher on this topic, take a look at our course Beginning RecyclerView.

The Android developers website also has a comprehensive article, Create a List with RecyclerView.

What Are Support Libraries?

Android Support Libraries are packages that contain code. They support a specific range of Android platform versions and sets of features. Most of these support libraries are now part of the androidx namespace. This is the recommended set of libraries to use.

What Is an Intent?

Intents are messaging objects that trigger actions from other components. These target components can include services and activities.

Explicit Intent

An explicit intent specifies a particular destination for fulfillment. You can direct your intent to an external app. But an explicit intent commonly targets another component within your app. When using an explicit intent, your code must provide the name of the target app or component.

Implicit Intent

An implicit intent does not specify the target component. Instead, it states an action to perform. The Android system directs the intent to an external app capable of fulfilling it. For example, if your app needs to send an email, the Android system will select options from the email apps installed on the device. The user can select the desired email app.

Intents can be as simple or as complex as you want. For more information, you can review our Android Intents Tutorial with Kotlin.

What Is Localization? How Do You Do It in Android?

Localization is the ability of an app to support multiple languages, time zones, currencies, number formats, etc. This allows you to distribute your app widely to different countries and populations. Your app can bundle its localization through using Android’s resource directory framework, which specifies items (strings, images, layouts…) for different locales.

We also have a detailed tutorial on this topic, Android Localization: Getting Started.

What Is Android Jetpack?

Jetpack is a suite of libraries released by Android in 2018. Jetpack’s libraries provide code that works across the many Android devices currently in use. This makes it easy for developers to adhere to best practices!

If you’re new to Android Jetpack, please see our tutorial Introduction to Android Jetpack for help.

Otherwise, let’s go check the most important libraries in Jetpack and the ones you may need in an interview.

What are Android Architecture Components?

Architecture Components are a collection of libraries included in Jetpack. They help you implement clean architecture in your app, based primarily on the MVVM (Model-View-ViewModel) pattern.

We have many tutorials on architecture components, but you can start with this one: Android Jetpack Architecture Components: Getting Started.

Android robot building with legos

What is Data Binding?

The Data binding library helps you bind UI components in your layouts to data sources in your app. It uses a declarative format.

For an explanation on how to use data binding, take a look at Data Binding in Android: Getting Started, by me! :]

What Is View Binding?

View binding replaces findViewById. It uses binding classes to do this. These classes contain references to all views that have an ID in the corresponding layout.

You can learn more about view binding in our View Binding Tutorial for Android: Getting Started.

What Is LiveData?

LiveData is an observable class. The advantage of LiveData over libraries like Rx is that it is lifecycle-aware. It only updates data in the STARTED or RESUMED state.

LiveData is closely related to coroutines, covered elsewhere in this article. If you want a better understanding of how everything works together, see our article Coroutines with Lifecycle and LiveData.

What Is Room?

Room is a persistence library built over SQLite to help you create databases more easily. Room uses caching to persist your app’s data locally. This provides the app with consistent data, regardless of internet connectivity.

What Is ViewModel?

ViewModel is a class that stores the data from your UI. Because it’s aware of the app’s lifecycle, ViewModel is able to persist UI data through configuration changes, such as screen rotations.

What Is the Navigation Component?

The navigation component is a framework that controls navigation within an Android app. It manages the back stack. It also handles functions with different controls, such as the app bar or drawers. The navigation component helps you provide a consistent user experience by enforcing established navigation principles.

Other Libraries

In the Android world, you’ll encounter many libraries in addition to those in Jetpack. Your interviewer may ask about these. Here are some of the most common:

  1. Libraries for network requests: Retrofit, GraphQL
  2. Libraries for images: Picasso
  3. Dependency Injection: Dagger
  4. Reactive Programming: RXJava and RXKotlin

Where Do You Organize Your Tests in Android?

When you create an Android Studio project, you create two directories for testing:

  1. The test directory is for unit tests that run locally. Usually, the JVM runs these tests.
  2. The androidTest directory is for tests that run on devices. You’ll use this directory for other kinds of tests, such as integration tests and end-to-end tests.

What Are Unit Tests? How Do You Do Them in Android?

Unit tests run locally. Since they aren’t run on a device, they don’t have access to any Android framework library. It’s possible to use libraries that allow you to call Android framework methods from unit tests, however these libraries substitute only simulate device behavior. The preferred libraries are either JUnit or Mockito.

The ability to design and implement unit testing is usually a requirement for mid-senior to senior levels. If you want to learn how to do this, here are some resources:

Understanding how to use either of these test libraries will be enough for interviews.

Instrumentation Tests

Instrumentation tests are quite similar to unit tests but depend on a device or simulator to run. Since instrumentation tests are run on device, you have access to the Android device libraries. The two libraries mentioned above, JUnit and Mockito, are also used for instrumentation tests.

UI Tests

UI tests simulate a user’s interactions with your UI. The most popular library for testing is Espresso. You can learn about UI testing in our tutorial
Espresso Testing and Screen Robots: Getting Started.

Kotlin

The next questions cover Kotlin as the primary Android programming language. Most of today’s projects are written in Kotlin. And most shops have migrated their older projects to it as part of their ongoing maintenance.

Note: When interviewing for a position as an Android developer, you may also encounter Java questions. Java is out of scope for this article.

Android robot with Kotlin cheatsheet

What Are Coroutines?

Coroutines are pieces of code that convert asynchronous callbacks for long-running tasks into sequential code. They make asynchronous programming much easier in Kotlin and Android.

Coroutines can be a confusing topic if you haven’t used them before. But you’ll love how they make your life easier! To learn more about coroutines, take a look at our Kotlin Coroutines: Fundamentals.

What Are Companion Objects?

Companion Objects are objects in your Kotlin file. They contain functions or properties that are tied to the class rather than to instances of it. They are similar to static members in other languages. Here’s an example:

class MyLoginFragment : Fragment(R.layout.fragment_my_login) {
  
  ...

  companion object {
        private const val TAG = "MyLoginFragment"
    }
}

For more information on companion objects, you can view our video
Companion Objects. This video is one episode of our course Programming in Kotlin: Functions & Custom Types.

How and When Do You Use Nullables in Kotlin?

Kotlin apps distinguish between elements that can be null and those that can’t. This special feature in Kotlin helps you avoid errors from null references. These errors are common in other languages!

Here’s an example of a variable that is not nullable:

var myVariable: String = "variable is not nullable"
myVariable = null //Compiler error. You can't do this!

And here’s what the same variable would look like if it were nullable:

var myVariable: String? = "This is my nullable variable"
myVariable = null

Notice the ? symbol. That’s how you identify an item as nullable.

For a more in detail explanation on nullables, please see our video Create and Consume Nullables. This is one episode in our Programming in Kotlin: Fundamentals
course.

How Do You Do Type Checking in Kotlin?

Kotlin uses the operator is, and its opposite, !is, for type checking. These operators return a boolean value. You run a type check to validate the type of the incoming value before performing an operation on it. Look at this example:

if (name is String) {
    // do my operation if name is a String
}

if (name !is String) { 
    // do my operation if name is not a String
}

This check prevents errors that can occur when you attempt to perform an operation on a value with an unexpected type.

How Do You Declare Switch Statements in Kotlin?

In Kotlin, you use the when keyword where you would use switch in some other languages. Here’s an example:

when (lotteryNumber) {
    329013 -> print("You won!!!")
    else -> print("Sorry you didn't win the lottery, try again!")
}

For a more comprehensive look at the when expression, see our video Simplify Code With When Expressions. This video is part of our course Programming in Kotlin: Fundamentals.

What Is a Lambda Expression?

A lambda is a function that is not declared, but is passed immediately as an expression.

val amountOfCandies = { 
  candiesStored: Int, candiesBought: Int -> candiesStored + candiesBought 
}

Cool right? Simple, concise, and no return statement needed :] Best of all, it can be passed around as a parameter to other functions.

If you want a better understanding of lambdas, see our tutorial Introduction to Kotlin Lambdas: Getting Started.

When Is the Keyword it Used in Lambda Expressions?

When you have a lambda expression with a single parameter, you can use the keyword it to refer to that parameter.

val isPositiveNumber = {
    it > 0
}

Again, you can learn more about lambdas in our tutorial Introduction to Kotlin Lambdas: Getting Started.

What Is a Class Extension?

Extensions exist in many programming languages. As their name states, they “extend” the functionality of a class.

Take a look at this example of an extension on String. This one validates an email address:

// 1
import java.util.regex.Pattern

// 2
fun String.isEmailAddressValid(): Boolean {
  // 3
  val expression = "^[\\w.-]+@([\\w\\-]+\\.)+[A-Z]{2,8}$"
  val pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE)
  val matcher = pattern.matcher(this)
  // 4  
  return matcher.matches()
}

Here’s what you’re doing in this code:

  1. You import the Java library for regex patterns.
  2. You declare the function expression. Notice that the name of the class it’s extending, String, precedes the name of the function isEmailAddressValid().
  3. Here you create three constants:
    • The first constant contains a regular expression for emails.
    • The second constant creates a pattern matcher. Notice that it is not case sensitive.
    • The third constant makes it a pattern matcher.
  4. Finally, you run matches on it. This function returns a boolean value that tells you whether the data entered is an email or not.

Extensions are very useful. Demonstrating that you know how to apply them correctly will definitely help your interview! Read more on this topic in our article Kotlin Android Extensions.

What Are Ranges in Kotlin?

The term range is very similar to its equivalent in math. It represents a group of numbers that goes from a lower to a higher bound (or the other way around). Look at the example below to see how it looks in code:

i in 1..10  // equivalent of 1 <= i && i <= 10

Notice the range has two dots between the numbers. To iterate down instead up, use the keyword downTo instead of the two dots:

i in 1 downTo 10

If you want to broaden your knowledge of the Kotlin language, review our Programming in Kotlin: Fundamentals and Programming in Kotlin: Functions & Custom Types courses.

Object-Oriented Programming

As an Android developer, you will write code using Object-Oriented Programming. Many interviews will include general questions on OOP.

What Is Polymorphism?

The word polymorphism means having multiple forms. In OOP, the most general definition of polymorphism is the ability to define one interface or class with many implementations. In Android, there are two types of polymorphism, dynamic and static.

In dynamic polymorphism, the type of object on which method is being invoked is not known at compile time but will be decided at run time. For example, a parent class Animal might have two subclasses, Dog and Cat, both inheriting from Animal.

Static polymorphism refers to constructors. You can have multiple constructors with the same name, but they can receive different parameters. The intended constructor will be executed depending on the arguments passed.

For example, a school system uses an app to maintain student information. You write a constructor to create a student object:

fun createStudent(name: String, nickname: String) {
  addStudentToDatabase(name: String, nickname: String)
}

Some students, but not all of them, play sports. You write another constructor to create an object for a student who plays sports:

fun createStudent(name: String, nickname: String, sport: Sport) {
  addStudentToDatabase(name: String, nickname: String)
  assignSportToStudent(sport: Sport)
}

This second constructor will also create a student object, just as the first one does. But afterward, it will also assign the desired sport. The compiler determines which constructor to execute based on the parameters it receives.

What Is the Difference Between a Class and an Object?

A class is a blueprint or template for creating objects. An object is an instance of a class.

Classes don't contain actual data. Classes can have sub-classes, but once you create an object, it remains an instance of the class or sub-class you created it from.

Seal with Kotlin logo

What Are Data Classes?

A data class in Kotlin is a special type of class that exists only to contain data. You declare a data class by providing the name of the class and its attributes, as in this example:

data class Cat(val name: String, val age: Int, val furColor: Color)

This special construct in Kotlin provides standard functionality with minimal coding. Behind the scenes, Kotlin generates getters and setters and an initializer for you. Then you can get on with creating and modifying instances of the object!

For a deeper dive into data classes, see the Data Classes article in the Kotlin Language website.

What Is Encapsulation?

Encapsulation is a primary concept of Object-Oriented Programming. It refers to the bundling of an object with its attributes, state and operations. This simplifies code and protects data integrity.

What Are Visibility Modifiers?

Data encapsulation allows you to control how objects and their behaviors are exposed outside the object. This is called visibility. In Kotlin, there are four levels of visibility, called visibility modifiers: public, internal, protected, and private. The default is public.

For more information about Kotlin's visibility modifiers, review the Visibility modifiers article in the Kotlin website.

Where to Go From Here?

In this Android Interviewing tutorial, you reviewed the most important topics you'll encounter in an interview, regardless of your level. There are many other topics you may want to review. See the suggestions below for some other resources.

Design patterns are a very broad topic on Android. Most interviewers will ask you which ones you have used, and they'll ask you to describe a couple of them. Visit our Common Design Patterns for Android with Kotlin tutorial to learn about them.

It is common in interviews to have whiteboard questions related to data structures and algorithms. This is a huge topic by itself. We cover all the associated topics in our book Data Structures and Algorithms in Kotlin. If you have a coding interview, make sure you review these topics!

And if you are interviewing for a more advanced role, you may get architecture questions. For acing those interviews, take a look at our Advanced Android App Architecture Book.

If you have any suggestions, questions, or if you want to show off the new job you just got, join the discussion below.

Average Rating

5/5

Add a rating for this content

3 ratings

More like this

Contributors

Comments