Android Interview Question and Answer… Part — 2

Saqib Ahmed
7 min readMar 21, 2023

Hi All,

This is series of the android interview question and answer… check out the first part in the link below…

Jetpack Library:

  1. What is the difference between the view binding and data binding?

Data Binding: The Data Binding Library is an Android Jetpack library that allows you to bind UI components in your XML layouts to data sources in your app using a declarative format rather than programmatically, reducing boilerplate code.

View Binding: View binding is a feature that makes it easier to write code that interacts with views. Once view binding is enabled in a module, it generates a binding class for each XML layout file present in that module. An instance of a binding class contains direct references to all views that have an ID in the corresponding layout.

— for more details click here

2. What is a WorkManager in android?

Android WorkManager is a background processing library which is used to execute background tasks which should run in a guaranteed way but not necessarily immediately. With WorkManager we can enqueue our background processing even when the app is not running and the device is rebooted for some reason.

Note: WorkManager sits on top of a few APIs such as JobScheduler and AlarmManager. WorkManager picks the right APIs to use, based on conditions like the user's device API level.

import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters

class UserDataUploadWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {
override fun doWork(): Result {
// do upload work here
return Result.success()
}

}

3. What are the three main components of a room database?

The three major components of Room are:

  • Database: It represents the DB, it is an object that holds a connection to the SQLite DB and all the operations are executed through it.
  • Entity: Represents a table within the Room Database.
  • DAO: An interface that contains the methods to access the Database.

For More details — click here

4. What is a foreign key in Room DB? Why do we use it?click here

5. what is the advantage of using Preference Datastore API over shared Preference?

DataStore has many benefits over SharedPreferences. One is support for coroutines and flow, which makes asynchronous reads and writes possible and safe to call from the UI thread.

Another main advantages of DataStore over SharedPreferences is its neat mechanism for catching and handling exceptions. While SharedPreferences throws parsing errors as runtime exceptions, leaving room for unexpected, uncaught crashes, DataStore throws an IOException when an error occurs with reading/writing data.

For more details — click here

6. What is a Scope Storage in Android? What are the benefit of using scoped storage? — Click here

7. What do you think about NavHost in navigation? — click here

8. What does the “@module ” annotation in the dagger hilt dependency Injection ? — click here.

9. What is the FCM in Firebase?

Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably send messages at no cost.

  • Send notification messages or data messages.
  • Versatile message targeting.
  • Send messages from client apps.

10. What are the types of Events in Firebase?

There are different types of event available in the Firebase:

  • child_added − This event type will be triggered once for every player and every time a new player is added to our data.
  • child_changed − This event type is triggered when the data has changed.
  • child_removed − This event will be triggered once every time a child is removed.

Coroutine & Flow :

  1. what is the difference between a thread and coroutine?

A coroutine is a lightweight thread that can suspend its execution and resume later without blocking the main thread. A thread, on the other hand, is a heavier weight process that can run concurrently with other threads. Coroutines are more efficient and easier to use than threads.

For more details — click here.

2. what are the types of dispatcher in the coroutine?

There are 4 types of Dispatchers in Kotlin Coroutines:

  • Dispatchers.Default
  • Dispatchers.IO
  • Dispatchers.Main
  • Dispatchers.Unconfined

3. what is different between async and launch method in coroutine?

The difference is that the launch{} returns a Job and does not carry any resulting value whereas the async{} returns an instance of Deferred<T> , which has an await() function that returns the result of the coroutine like we have future in Java in which we do future. get() to get the result.
For more details — click here

4. How do call the coroutine in parallel? — click here

5. What is a flow in Android programming?

A flow in Android programming is a reactive programming construct that represents a stream of data that can be asynchronously emitted by a producer and consumed by a consumer. It is used to handle streams of data such as database queries, network requests, and sensor data.

6. What is the difference between a flow and a live data?

A flow in Android programming is a reactive programming construct that represents a stream of data that can be asynchronously emitted by a producer and consumed by a consumer. A live data, on the other hand, is an observable data holder that can be observed by a UI component. Flows are more flexible and can handle more complex data streams than live data.

7. What is a hot Flow and cold Flow?

Cold flows are created on-demand and emit data when they’re being observed.

Hot flows are always active and can emit data regardless of whether or not they’re being observed.

The main difference is that a cold flow is a type of flow that executes the producer block of code on-demand when a new subscriber collects. A hot flow is always active.

Security & Exception:

  1. What is Proguard?

Proguard detects and removes unused classes, fields, methods, and attributes. Mobile app development companies use the Proguard in android, it optimizes bytecode and removes unused instructions. It renames the remaining classes, fields, and methods by using short meaningless names.

2. What are the tools used to optimize and secure your application?

R8 is an tools for obfuscate and shrink the app. R8 is a java program shrinking and minification tool that converts java byte code to optimized dex code.

R8 determines entry points through -keep rules in the project’s R8 configuration files. That is, keep rules specify classes that R8 should not discard when shrinking your app, and R8 considers those classes as possible entry points into your app.

3. What is a secure boot in android?

Secure Boot is a security feature that ensures that the Android device boots using only trusted software. It verifies the digital signature of the boot loader and kernel, ensuring that they haven’t been tampered with or compromised in any way.

4. What is the difference between checked and unchecked exceptions in Android programming?

Checked exceptions in Android programming are exceptions that must be declared in the method signature, and the calling code must handle them. Unchecked exceptions, on the other hand, do not have to be declared or caught. They are typically caused by programming errors or invalid inputs.

Compose:

  1. What is a declarative approach in compose?

Declarative UI : This pattern is an emerging trend that allows the developers to design the user interface based on the data received. This on the other hand focuses on the “what. This design paradigm makes use of one programming language to create an entire application.

2. Name some basic UI component in compose?
Some Basic UI Component to build in compose are

  • Row()
  • Column()
  • Box()
  • Text()
  • Button()
  • Spacer()
  • Divider()
  • TextField()

3. What is a Launched Effect in compose?

As LaunchedEffect is a composable function, it can only be used inside other composable functions. In order to launch a coroutine outside of a composable, but scoped so that it will be automatically canceled once it leaves the composition.

for more details — click here

@Composable
fun LandingScreen(onTimeout: () -> Unit) {


val currentOnTimeout by rememberUpdatedState(onTimeout)

LaunchedEffect(true) {
delay(SplashWaitTimeMillis)
currentOnTimeout()
}

/* Landing screen content */
}

4. What are the benefits of using Jetpack compose?

Benefit of using compose.

  • It is very fast and offers a smooth performance.
  • It’s simple to learn.
  • It is possible to interoperate with an imperative approach.
  • Offers a better way to implement loose coupling principles.
  • It is 100% made in Kotlin which makes it a modern approach in Android development.
  • it support the functional programming to increase the productivity.

5 . What is a Composable function?

Composable functions are the fundamental building blocks of an application built with Compose. It can be applied to a function or lambda to indicate that the function/lambda can be used as part of a composition to describe a transformation from application data into a tree or hierarchy. It is annotated by “composable”.

Architecture:

  1. What is difference between the MVI, MVP and MVVM architecture? — click here.
  2. Name some design pattern in android? — click here.
  3. What is a SOLID principle? — click here.
  4. Give a brief idea about Android application architecture?

The architecture of Android application has few components, which have their functions to perform:

  • Service: It performs the background functions
  • Intent: Performs the interconnection function between activities and data passing mechanism
  • Resource: Externalization it is used to perform strings and graphics functions
  • Notification: This shows the lights, sound, icon, notification, incoming chats messages dialogue box, etc.
  • Content providers: It shares the data between applications.

Programming & Coding:

Here, they will test your programming skills , they would have ask you to write code. Basically, any sample logic which you could get in website like LeetCode, HackerRank, Codechef…etc. You can practice it from any coding website.

I hope this article will find you helpful in preparing and cracking the android interview.

Wishes you best of luck for the interview. Thank you for reading !!!

--

--

Saqib Ahmed

I'm basically a mobile developer and became a self-time freelance writer. I spend most of my time with tech related stuff. I’m sharing my learning with you!