Android Interview Question and Answer… Part — 1

Saqib Ahmed
10 min readMar 19, 2023

Interview is one part of the process to measure the candidate skills , ability and knowledge. Every interviewer has some basic expectation from the interviewee that should posses. so they classify the technical part in terms of the skills, ability and knowledge.

From the android process perspective , the interviewer first look for the programming language that candidate are familiar with then understanding of android OS, SDK and it’s feature , architecture of the application development, building feature , testing and maintenance of an application.

Here some of the example of the interview question.

Java:

  1. What is the difference between encapsulation & abstraction?click here.
  2. What is the difference between HashMaps vs HashTables?click here.
  3. What is a volatile and transient Keyword?
  • The Volatile keyword is used to mark the JVM and thread to read its value from primary memory and not utilize cached value present in the thread stack. It is used in concurrent programming in java.
  • The Transient keyword is used with the instance variable to eliminate it from the serialization process. During serialization, the value of the transient field or variable is not saved.

4. Why is string immutable in java? click here.

5. What is a string pool in java?

String pool is nothing but a storage area in Java heap where string literals stores. It is also known as String Intern Pool or String Constant Pool. It is just like object allocation. By default, it is empty and privately maintained by the Java String class. Whenever we create a string the string object occupies some space in the heap memory. Creating a number of strings may increase the cost and memory too which may reduce the performance also.

6. What is a Thread and Thread pool in Java?click here.

7. Explain @jvmstatic @jvmoverloads @jvmfiled? — click here.

8. Explain multithreading. How two threads pass messages internally? — click here.

9. What is the main objective of garbage collection?

The main objective of this process is to free up the memory space occupied by the unnecessary and unreachable objects during the Java program execution by deleting those unreachable objects.

  • This ensures that the memory resource is used efficiently, but it provides no guarantee that there would be sufficient memory for the program execution.

10. What are the different types of Thread Priorities in Java? And what is the default priority of a thread assigned by JVM?

There are a total of 3 different types of priority available in Java.

MIN_PRIORITY: It has an integer value assigned with 1.
MAX_PRIORITY: It has an integer value assigned with 10.
NORM_PRIORITY: It has an integer value assigned with 5.

In Java, Thread with MAX_PRIORITY gets the first chance to execute. But the default priority for any thread is NORM_PRIORITY assigned by JVM

Kotlin:

  1. what is advantage & disadvantage of Kotlin? — click here.
  2. Difference between lateinit and lazy?
  • Lazy initialization is one of the properties of Delegate-s, while late initialization(lateinit) requires the use of a language keyword.
  • Lazy initialization applies only to val, and late initialization(lateinit) applies only to var fields.
  • We can have a lazy field of a primitive type, but lateinit applies only to reference types.

2. What is the key difference between Iterable<T> and Sequence<T> in Kotlin? — click here.

3. Is kotlin pass by reference or value ? — click here.

4. What is a Range Operator in kotlin?

  • This operator is used to mention a range of values inclusive of the from and to values.
  • It is represented by “..”
  • This operator can be used only in the increasing order of ranges.
  • Range operators are mainly used along with in and !in operators.
  • While using range operator for iterating through a range, it is possible to set a range even skipping values. This is done using “step” keyword.
if (i in 1..4) { // equivalent of i >= 1 && i <= 4
print(i)
}

5. What are the visibility modifier in kotlin?

There are four visibility modifiers in Kotlin: private, protected, internal, and public.

6. Difference between state flow and shared flow?

7. What is a Higher order function in kotlin?

A higher-order function is a function that takes functions as parameters, or returns a function.

8. What is the Companion Object in Kotlin?

In Kotlin, if you want to write a function or any member of the class that can be called without having the instance of the class then you can write the same as a member of a companion object inside the class. So, by declaring the companion object, you can access the members of the class by class name only(which is without explicitly creating the instance of the class).

class CompanionClass{
companion object {
fun test() { ... }
}
}

9. What is Inline Function in Kotlin?

  • The higher-order functions or lambda expressions, all stored as an object so memory allocation, for both function objects and classes, and virtual calls might introduce runtime overhead. Sometimes we can eliminate the memory overhead by inlining the lambda expression.
  • In order to reduce the memory overhead of such higher-order functions or lambda expressions, we can use the inline keyword which ultimately requests the compiler to not allocate memory and simply copy the inline code of that function at the calling place.

10. What is a Sealed Class in Kotlin?

  • Sealed classes and interfaces represent restricted class hierarchies that provide more control over inheritance.
  • All direct subclasses of a sealed class are known at compile time. No other subclasses may appear outside a module within which the sealed class is defined.
  • Sealed class is nothing but a Enum class with booster.

Android:

  1. What are the application components in Android?

There are four application components in android namely,

  1. <activity> — Activity
  2. <service> — Service
  3. <receiver> — Broadcast Receiver
  4. <provider> — Content Provider

2. What is AAPT?

AAPT is Android Asset packing tool. This provides developers with the ability to deal with zip-compatible archives, and it includes creating, extracting as well as viewing its content.

3. Difference between viewmodel and activity viewmodel?

- ViewModels() gives you the ViewModel instance scoped to the current fragment. This will be different for different fragments.

- ActivityViewModels() gives you the ViewModel instance scoped to the current activity. Therefore the instance will remain the same across multiple fragments in the same activity.

~~~~Note: You cannot have a shared viewmodel for two activities, means that, you cannot create the same instance of the viewmodel in two activities.

4. What is the difference between Gson and Moshi Library?

Moshi is fast! It is a replacement to Gson converter, it is written in kotlin and java, and supports most kotlin libraries, it supports the default value.

5. What is a caching in retrofit ? — click here

6. Difference between getLayoutPosition vs getAdapterPosition?

getLayoutPosition:

RecyclerView isolates the data set from how we display it that why we use LayoutMangers to manage the way we display the data from the data set and the RecyclerView updates the Layout with the logic of batches which means that it waits for changes to be done and then passes those changes to the layout. This waiting period is less than 16 ms so in most times you won’t find any difference between getAdapterPosition and getLayoutPosition because of this small period of waiting time but it is still possible to find that you need to get the position in terms of the updated layout

getAdapterPosition:
The ViewHolder provides us the getAdapterPosition which always has the updated adapter’s position of this holder. What does that mean ? It means that whenever you click on an item (ViewHolder item) we ask the adapter about its position. so you will get the latest position of this item in terms of Adapter’s logic.

7. What is the difference between serialization and parcelable?

Serializable

Serializable is a standard Java interface. You can just implement a Serializable interface and add override methods. The problem with this approach is that reflection is used and it is a slow process. This method creates a lot of temporary objects and causes quite a bit of garbage collection. However, Serializable interface is easier to implement.

Parcelable

Parcelable process is much faster than Serializable. One of the reasons for this is that we are being explicit about the serialization process instead of using reflection to infer it. It also stands to reason that the code has been heavily optimized for this purpose.

8. What is the type of launch Mode in android activity?

There are basically four types of launch mode.

  1. Standard
  2. Single task
  3. Single top
  4. Single Instance

9. How do you find the memory leak in android?

There are several ways to do so…

  • Check for any register of broadcast receiver in the code and forget to unregister it. that’s causes the memory leak.
  • Detecting memory leak’s using android studio monitor’s tools.
  • Detecting using the Leak Canary library.
    For More… Check here

10. What is Android Debug Bridge(ADB)?

Android Debug Bridge is a command-line tool used to allow and control communication with an emulator instance. It gives the power for developers to execute remote shell commands to run applications on an emulator.

11. What is DDMS?

DDMS(Dalvik Debug Monitor Server) is a debugging tool in the Android platform. It gives the following list of debugging features:

  • Port forwarding services.
  • Thread and heap information.
  • Logcat.
  • Screen capture on the device.
  • Network traffic tracking.
  • Incoming call and SMS spoofing.
  • Location data spoofing.

12. What is AIDL? Which data types are supported by AIDL?

AIDL(Android Interface Definition Language) is a tool that handles the interface requirements between a client and a service for interprocess communication(IPC) to communicate at the same level.

The process involves dividing an object into primitives that are understood by the Android operating system. Data Types supported by AIDL is as follows:

  • String
  • List
  • Map
  • CharSequence
  • Java data types (int, long, char, and boolean)

13. Explain Sensors in Android?

Android-based devices have a collection of built-in sensors in them, which measure certain parameters like motion, orientation, and many more through their high accuracy. The sensors can be both hardware and software based on nature. There are three prominent categories of sensors in Android devices. They are:

  • Position Sensor: It is used for measuring the physical position of the Android device. This has orientation sensors and magnetometers.
  • Motion Sensors: These sensors consist of gravity, rotational activity, and acceleration sensors which measure the rotation of the device or the acceleration, etc.
  • Environmental Sensor: It includes sensors that measure temperature, humidity, pressure, and other environmental factors.

14. What is AndroidManifest.xml file and why do you need this?

  • The AndroidManifest.xml file contains information regarding the application that the Android system must know before the codes can be executed.
  • This file is essential in every Android application.
  • It is declared in the root directory.
  • This file performs several tasks such as:
  1. Providing a unique name to the java package.
  2. Describing various components of the application such as activity, services, and many more.
  3. Defining the classes which will implement these components.

15. What is ANR in Android? What are the measures you can take to avoid ANR?

ANR(Application is Not Responding) is a dialog box that appears when the application is not responding. This ANR dialogue is displayed whenever the main thread within an application has been unresponsive for a long time under the following conditions:

  • When there is no response to an input event even after 5 seconds.
  • When a broadcast receiver has not completed its execution within 10 seconds.

Following measures can be taken to avoid ANR:

  • An application should perform lengthy database or networking operations in separate threads to avoid ANR.
  • For background task-intensive applications, you can lessen pressure from the UI thread by using the Intent Service.

16. What is the significance of the .dex file?

Android programs are compiled into a .dex file (Dalvik Executable file) by DVM, which are then zipped into a .apk file on the device. .dex files are created by translating compiled applications written in java. .dex is a format that is optimized for effective storage and memory-mappable executions

17. What is context in Android?

The context in Android is the context of the current state of the application or object. The context comes with services like giving access to databases and preferences, resolving resources, and more.

There are two types of context. They are:

Activity context

  • This activity context is attached to the lifecycle of an activity.
  • The activity context can be used when you are passing the context in the scope of an activity or you need the context whose lifecycle is attached to the context of the activity.

Application context:

  • This application context is attached to the lifecycle of an application.
  • The application context should be used where you need a context whose lifecycle is separate from the current context or when you are passing a context beyond the scope of activity.

18. Explain the difference between Implicit and Explicit Intent?

  • An Explicit Intent is where you inform the system about which activity should handle this intent. Here target component is defined directly in the intent.

For example,

val i: Intent = Intent(this, Activitytwo.class::java)
i.putExtra("Value1","This is ActivityTwo")
i.putExtra("Value2","This Value two for ActivityTwo")
startactivity(i)

Implicit Intent:

  • An Implicit Intent permits you to declare the action you want to carry out. Further, the Android system will check which components are registered to handle that specific action based on intent data. Here target component is not defined in the intent.

For example,

val intent: Intent = Intent(ACTION_VIEW,Uri.parse("http://www.xyz.com"))
startActivity(intent)

19. What are broadcast receivers? How is it implemented?

A broadcast receiver is a mechanism used for listening to system-level events like listening for incoming calls, SMS, etc. by the host application. It is implemented as a subclass of BroadcastReceiver class and each message is broadcasted as an intent object.

public class MyReceiver extends BroadcastReceiver 
{
public void onReceive(context,intent){}
}

20. What is a Build Type in Gradle?

Build Type is a build and packaging settings like signing configuration for a project. For instance, debug and release build types. The debug build type will use an android debug certificate for packaging the APK file. While the release build type will use a user-defined release certificate for signing and packaging the APK.

Will be continue in the next part…. Thank you.

Check out the second part in the below link.

--

--

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!