Open In App

Top 25 Android Interview Questions and Answers For Experienced

Improve
Improve
Like Article
Like
Save
Share
Report

The need for new technologies and their developers is increasing as the world is dynamically transforming digitally. Everyone nowadays relies on apps for a variety of functions, including acquiring information and keeping in touch with one another as well as daily activities like shopping, commuting, and bill payment. But have you wondered how much Android Developers are getting paid to do all these things? PayScale estimates that the annual compensation for an Android Software Engineer in India is ₹3,99,594. Here’s why you need to be thorough with the Top 25 Advanced Android Interview Questions to ace interviews in both product and service-based companies. 

Android Interview Questions and Answers for Experienced Android Developers

Likewise, the average income for an experienced Android developer in India is ₹13,16,973/-.  When it comes to Android Developer Salaries in the United States and the United Kingdom, the figures are $113,900 and £35,554, respectively. 

Many Android Developers are being hired by big giants like Google, Amazon, Facebook, and others as well as growing startups like Zomato, Paytm, and CRED. If you wish to be employed by one of these companies, go through these top 25 Advanced Android Interview Questions and their Answers to ace in interviews:

Q1. What are the Lifecycle Events of an Android Activity?

Lifecycle is an Android Architecture Component released by Google to assist all Android developers. The Lifecycle is a class/interface that maintains information about an activity/fragment’s current state and allows other objects to see this state by keeping track of it. The events of an Android component’s lifecycle, such as those of an activity or fragment, are the focus of the lifecycle component.

There are three major classes to deal with it:

  1. Lifecycle
  2. Lifecycle Owner
  3. Lifecycle Observer

A. Lifecycle

A lifecycle is a method that provides information on the Events that took place in relation to an activity or fragment. We have a lifecycle class that uses the enumerations State and Event to track the various components. The lifecycle is determined by Events and States. Every event has a unique state.

Event

                      State

 OnCreate() Called when the activity is first created.
 OnStart() Called when the activity becomes visible to the user.
 OnResume()    Called when the activity starts interacting with the user.
 OnPause() Called when the current activity is being paused and the previous activity is resumed.
 OnStop() Called when the activity is no longer visible to the user.
 OnDestroy() Called before the activity is destroyed by the system(either manually or by the system to conserve memory
 OnRestart() Called when the activity has been stopped and is restarting again.

B. Lifecycle Owner

There is a Lifecycle for every Activity. This Activity will be the lifecycle owner. LifecycleOwner is the one who will be constructed first when an activity is initialized. Android LifeCycle is indicated by any class that implements the LifeCycleOwner interface. Fragments and Activities, for instance, implement the LifeCycleOwner interface as of Support Library version 26.1.0. By using a LifeCycleRegistry and the interface as defined above, one can develop unique LifeCycleOwner components.

C. Lifecycle Observer

The Lifecycle Observer observes the activity, records the lifecycle, and takes action. This lifecycle Observer’s activity is dependent on the lifetime of the lifecycle Owner. Every lifecycle owner has a lifecycle, and the lifecycle observer acts in response to an event or state in the owner’s lifecycle.

Get to know more with an Example: Activity Lifecycle in Android with Demo App

Lifecycle of an Android App

 

Q2. How can Two Distinct Android Apps Interact?

On Android, there are essentially two ways for apps to communicate with one another:

  • Intents, which allow data to be passed from one program to another, and
  • Services, which allow one app to offer functionality to other apps.

Q3. How would you communicate between Two Fragments?

All communication between fragments occurs either through a shared ViewModel or through the related Activity. Direct communication between two Fragments should not be allowed.

To communicate across fragments, it is advised to make a shared ViewModel instance. Both fragments have access to the ViewModel via the Activity that contains them. If the data is exposed using LiveData, the other fragment will be pushed with the updated data as long as it is monitoring the LiveData from the ViewModel. The fragments can update data within the ViewModel.

Get to know more with an Example: How to Communicate Between Fragments in Android?

Q4. What is Android Data Binding?

A support library called the Data Binding Library allows you to take advantage of binding UI components to data sources in a layout using a declarative format.

Layouts are frequently defined in activities using code that invokes UI framework APIs. For instance, in the code below, the userName field of the viewModel variable is bound to a TextView widget by calling findViewById() to locate the widget:

TextView textView = findViewById(R.id.sample_text);
textView.setText(viewModel.getUserName());

The subsequent section illustrates how to assign text to the widget directly in the layout file using the Data Binding Library. By doing this, none of the Java/Kotlin code from the previous example is necessary.

<TextView android:text="@{viewmodel.userName}" />

The pros of using Android Data Binding:

  • Decreases the amount of boilerplate code, which results in
    • Less coupling
    • Improved readability
    • A custom view with a strong, simple-to-implement custom property
  • Faster than findViewById
    • The binding extracts the Views with IDs in a single trip across the View Hierarchy.
    • When using this method with several Views, findViewById may take longer.

Get to know more with an Example: Data Binding in Android with Example

Q5. What is a ViewHolder Pattern? Why should We use it?

When the adapter calls the getView() function, it also calls the findViewById() method. As a result of the mobile CPU having to perform such heavy lifting, the application’s performance suffers and battery life degrades. FindViewById shouldn’t be used repeatedly. Instead, utilize the ViewHolder design pattern.

The efficiency of the application improves because a ViewHolder stores a reference to the id of the view resource, eliminating the need to “find” it again later.

Q6. What is the difference between Handler, AsyncTask, and Thread?

  • The Handler class offers a straightforward route for sending data to this thread and can be used to register to a thread. When using another background thread, a handler enables you to connect with the UI thread.
  • The establishment of a background process and synchronization with the main thread are both handled by the AsyncTask class. Additionally, it allows for reporting on the status of ongoing tasks.
  • A developer can employ a Thread, which is the fundamental building block of multithreading, with the following drawback:
    • Handle synchronization with the main thread if you post back results to the user interface
    • No default for canceling the thread
    • No default thread pooling
    • No default for handling configuration changes in Android

Q7. Discuss Singletons vs Application Context for the app-global state.

Static singletons may usually perform the same purpose in a more scalable way. If your singleton requires a global context (for instance, to register broadcast receivers), you can provide a Context to the method that retrieves it, which internally uses Context. When creating the singleton for the first time, use getApplicationContext().

However, singletons are difficult to test and, if lazily initialized, introduce an indeterminism state with undetectable side effects. Another issue that has been raised is visibility, and since singletons imply global (= random) access to shared states, subtle flaws may appear when concurrent programs are improperly synchronized.

Despite being a singleton in and of itself, the app context is maintained by the framework and has a clearly defined life cycle, scope, and access path. Therefore, in my opinion, this is the only place where you should maintain an app-global state.

Q8. How can We use AsyncTask in different Activities?

One approach is to build a callback interface using AsynTask in several Activities.

Create a Callback Interface

interface AsyncTaskListener<T> {
    public void onComplete(T result);
}

Then in your MainActivity 

public class MainActivity extends AppCompatActivity implements AsyncTaskListener<String> {
    public void onComplete(String result) {
        // your code here
    }
}

and TestActivity

public class TestActivity extends AppCompatActivity implements AsyncTaskListener<String> {
    public void onComplete(String result) {
        // your code here
    }
}

And Add to your AsyncTask class:

public class JSONTask extends AsyncTask<String, String, String>
    private AsyncTaskListener<String> listener;

public JSONTask(AsyncTaskListener < String > callback) {
    this.listener = callback;
}

protected void onPostExecute(String result) {
    listener.onComplete(result);
    // calling onComplate interface
}

Q9. What is Android Jetpack Architecture Components?

You can create reliable, tested, and maintainable apps with the aid of the libraries that make up the Android Architecture Components. Android Jetpack includes Android Architecture Components.

Following are all of the Android architecture components:

  • Data Binding: It aids in declaratively connecting our app’s data sources and UI elements.
  • Lifecycles: It controls the fragment and activity lifecycles of our application, endures configuration changes, prevents memory leaks, and quickly loads data into our user interface.
  • LiveData: It alerts viewers to any database modifications. Build data objects that alert views to database changes by using LiveData. Everything required for in-app navigation in an Android application is taken care of.
  • Paging: It assists in gradually loading data from our data source as needed.
  • Room: It is a library for SQLite object mapping. Use it to quickly convert SQLite table data to Java objects while avoiding boilerplate code. The room offers SQLite statement compile-time checks and can produce RxJava, Flowable, and LiveData observables. It maintains UI-related data in a lifecycle-aware manner using the ViewModel. It keeps track of UI-related information that isn’t lost when a program rotates.
  • WorkManager: It controls all background tasks in Android under preset conditions.

Read More Here: Jetpack Architecture Components in Android

Q10. What are some differences between Parcelable and Serializable?

We cannot just transfer objects to activities in Android. The objects must either implement the Serializable or Parcelable interface to accomplish this.

An established Java interface is serializable. Simply implement the Serializable interface and provide the override methods. This method’s drawback is that reflection is employed, and it takes time. Serializable is substantially slower than a Parcelable operation.

This is due, in part, to the fact that we explicitly state the serialization procedure rather than letting reflection infer it. Furthermore, it makes sense that the code has been highly optimized with this end in mind.

Also:

  • The serializable interface is slower than Parcelable.
  • Compared to the Serializable interface, the Parcelable interface requires more effort to implement.
  • You can pass a Parcelable array using Intent.
  • Implementing a serializable interface is more straightforward.
  • The serializable interface produces several temporary objects and significantly increases the amount of garbage collection.

Q11. What is Broadcast Receiver?

Similar to the publish-subscribe design pattern, Android apps have the ability to transmit and receive broadcast messages from other Android apps and the Android system. The receiver component of an Android application is often referred to as the broadcast receiver. This component allows us to register receivers for any application- or system-level event. When that happens, the Android system will inform the registered receivers about the execution of the events in question.

Receivers can pick up one of two different kinds of broadcasts:

  1. Normal Broadcasts
  2. Ordered Broadcasts

Get to know more with an Example: Broadcast Receiver in Android With Example

Q12. What is MVVM in Android?

Model—View—ViewModel (MVVM) is the industry-recognized software Architecture Pattern that overcomes all drawbacks of MVP and MVC design patterns. MVVM suggests separating the data presentation logic(Views or UI) from the core business logic part of the application. 

The separate code layers of MVVM are:

  • Model: This layer is responsible for the abstraction of the data sources. Model and ViewModel work together to get and save the data.
  • View: The purpose of this layer is to inform the ViewModel about the user’s action. This layer observes the ViewModel and does not contain any kind of application logic.
  • ViewModel: It exposes those data streams which are relevant to the View. Moreover, it serves as a link between the Model and the View.

The description of Model is as follows:

  • MODEL: (Reusable Code – DATA) Business Objects that encapsulate data and behavior of application domain, Simply hold the data. 
  • VIEW: (Platform Specific Code – USER INTERFACE) What the user sees, The Formatted data. 
  • VIEWMODEL: (Reusable Code – LOGIC) Link between Model and View OR It Retrieves data from Model and exposes it to the View. This is the model specifically designed for the View.

Get to know more with an Example: How to Build a Simple Note Android App using MVVM and Room Database?

Q13. What is the difference between getContext(), getApplicationContext(), getBaseContext(), and this?

  • View.getContext(): Returns the context in which the view is executing at the moment. Typically, the active Activity.
  • Activity.getApplicationContext(): Returns the context for the entire application (the process all the Activities are running inside of). If you require a context linked to the lifetime of the entire application, not just the current Activity, use this in place of the current Activity context.
  • ContextWrapper.getBaseContext(): You use a ContextWrapper if you need access to a Context from within another context. GetBaseContext can be used to retrieve the Context that ContextWrapper is referring to.

This always refers to the current class object. getContext() is not always the same as this. For instance, in the Activity class, you can use this since Activity inherits from Context, but getContext() is not a function that is included in the Activity class.

Q14. What is Android Jetpack?

Android Jetpack is a set of software components, libraries, tools, and guidance to help in developing robust Android applications. Launched by Google in 2018, Jetpack comprises existing android support libraries and android architecture components with an addition of the Android KTX library as a single modular entity. Jetpack consists of a wide collection of libraries that are built in a way to work together and make robust mobile applications.

Its software components have been divided into 4 categories:

  1. Foundation Components
  2. Architecture Components
  3. Behavior Components
  4. UI Components

Key Benefits of Android Jetpack

  • Forms a recommended way for app architecture through its components
  • Eliminate boilerplate code
  • Simplify complex task
  • Provide backward compatibility as libraries like support are unbundled from Android API and are re-packaged to androidx.*package
  • Inbuilt productivity feature of the Kotlin Integration

Get to know more:

Q15. What is AndroidX?

The new open-source project known as Android Extension Library, also called AndroidX, is a considerable improvement over the original Android Support Library and can be used to create, test, package, and deliver libraries within Jetpack. The AndroidX namespace includes the Android Jetpack libraries. AndroidX is created independently of the Android OS and provides backward compatibility with earlier Android releases, much like the Support Library. The Support Library is entirely replaced by AndroidX packages, which provide feature parity and new libraries.

Additionally, AndroidX has the following functionalities as well:

  • A single namespace with the letters AndroidX contains all AndroidX packages. The Support Library packages have been mapped to the equivalent androidx.* packages.
  • Unlike the Support Library, AndroidX packages are individually updated and maintained. The AndroidX packages rigorously follow semantic versioning starting with version 1.0.0. The AndroidX libraries for a project can be independently updated.
  • All upcoming Support Library work will take place in the AndroidX library. This covers the maintenance of the original Support Library objects as well as the creation of new Jetpack components.

Q16. Explain Dependency Injection.

When a large number of objects have to be created that are dependent on a large number of other objects in a project, it becomes difficult as the project grows larger. With this increasing code base, good external support is required to keep track of everything. That is one of the scenarios in which we employ a Dependency Framework.

If we have two activities, Activity A and Activity B. Both require an object Downloader, which in turn requires the request. The request will now be dependent on Executor and HTTPClient. Dependency Injection is based on the concept of Inversion of Control, which states that a class’s dependencies should come from outside. In other words, no class should instantiate another class. Instead, instances should be obtained from a configuration class.

Dependency Framework is used for the following reasons:

  1. It facilitates the management of complex dependencies.
  2. It simplifies unit testing by allowing us to pass all external dependencies so that we can easily use mocked objects.
  3. It easily manages the object’s scope (lifecycle).
  4. This is why we need to use a Dependency Injection Framework in Android, such as Dagger.

Q17. What is Singleton Class in Android?

The Singleton Pattern is a software design pattern that restricts the instantiation of a class to just “one” instance. It is used in Android Applications when an item needs to be created just once and used across the board. The main reason for this is that repeatedly creating these objects, uses up system resources. The identical object should therefore only be created once and used repeatedly. It is utilized in situations where we only require a single instance of the class, such as with network services, databases, etc. We, therefore, create a singleton class to implement the Singleton pattern in our project or product. In this article, we’ll look at how to create singleton classes in Java and Kotlin.

Get to know more with an Example: Singleton Class in Android

Q18. What is Jetpack Compose in Android?

Jetpack Compose is a modern UI toolkit that is designed to simplify UI development in Android. It consists of a reactive programming model with conciseness and ease of Kotlin programming language. It is fully declarative so that you can describe your UI by calling some series of functions that will transform your data into a UI hierarchy. When the data changes or is updated then the framework automatically recalls these functions and updates the view for you.

Get to know more with an Example: Basics of Jetpack Compose in Android

Q19. What is Coroutine on Android?

Coroutines are lightweight threads that allow us to do synchronous and asynchronous programming with ease. We can build the main safety and replace callbacks with coroutines without blocking the main thread. The concurrency design pattern of the coroutine allows for code simplification and asynchronous execution, which can offer very high levels of concurrency with a very small overhead.

Get to know more with an Example: Coroutines in Android

Q20. What is Espresso in Android?

Google created the open-source Espresso testing framework for the Android user interface (UI). Espresso is an easy, efficient, and adaptable testing framework. Espresso tests avoid the distraction of boilerplate content, custom infrastructure, or complicated implementation details by stating expectations, interactions, and assertions in a straightforward and concise manner. Espresso tests execute really efficiently! It allows you to forego your waits, syncs, sleeps, and polls while manipulating and making assertions on the application UI while it is idle.

Get to know more with an Example: UI Testing with Espresso in Android Studio

Q21. Types of Notifications in Android.

Notifications could be of various formats and designs depending upon the developer. In General, one must have witnessed these four types of notifications:

  1. Status Bar Notification: Appears in the same brief layout as the current time and battery percentage.
  2. Notification Drawer Notification: Appears in the drop-down menu.
  3. Heads-Up Notification: Appears on the overlay screen, eg: Chat App notification and OTP messages.
  4. Lock-Screen Notification: Appears on the overlay of the locked screen if enabled.

Get to know more with an Example: Notifications in Android with Example

Q22. What is Firebase Cloud Messaging?

Firebase Cloud Messaging or FCM, originally known as Google Cloud Messaging or GCM, is a free cloud service provided by Google that enables app developers to deliver notifications and messages to users across many platforms, including Android, iOS, and web applications. It is a free real-time method for instantly sending notifications to client applications. Notifications with a payload of up to 4Kb can be properly transmitted via Firebase Cloud Messaging.

Q23. What is the Google Android SDK?

The Google Android SDK is a set of tools that developers use to create apps that run on Android-enabled devices. It includes a graphical interface that simulates an Android-driven portable environment, allowing them to test and debug their applications.

Q24. What is the difference between Volly and Retrofit?

Retrofit

Volley

Retrofit can parse many other types of responses automatically like:

  • Boolean: Web API response, to be a boolean.
  • Integer: Web API response, to be an integer.
  • Date: Web API response, to be a Long format date.
  • String: Web API response, to be in String format.
  • Object: Web API response, to be in a JSON object.
  • Collections: Web API response, to be in a String Format.
  • StringRequest: Request converts the response into a String.
  • JsonObjectRequest: Request and response automatically converted into a JSONObject.
  • JsonArrayRequest: Request and response automatically converted into a JSONArray.
  • ImageRequest: Request converts the response into a decoded bitmap.
Retrofit does not support caching. Volley has a flexible caching mechanism. When a request is made through volley first the cache is checked for an appropriate response. If it is found there then it is returned and parsed else a network hit is made.
Retrofit does not support any retrying mechanism. But it can be achieved manually by doing some extra code. In Volley, we can set a retry policy using the setRetryPolicy method. It supports the customized request timeout, number of retries, and backoff multiplier.
Retrofit has full support for Post Requests and Multipart uploads. Volley supports both post requests and multipart uploads but for post requests, we have to convert our java objects to JSONObject. Also for multipart uploads, we have to do some extra code and use some additional classes

Q25. Types of Databases in Android.

Relational, key-value, and object-oriented databases are the three main types of databases used by Android devices.

  1. SQLite: A well-known relational mobile database that is available on both Android and iOS.
  2. ORMLite: A lightweight Object Relational Mapper or ORM designed for Java/Kotlin applications, including Android.
  3. Room: An abstraction layer that sits on top of SQLite. Uses database classes as the primary access point for the persisted data and the means by which the database is maintained.
  4. Firebase Cloud Firestore or Realtime Database: Comprehensive multifunctional platform with a broad variety of goods, such as Cloud Firestore and Realtime Database.
  5. Realm: A quick, expandable replacement for SQLite that makes modern mobile applications’ data storing, querying, and synchronizing processes simple.


Last Updated : 16 Aug, 2023
Like Article
Save Article
Next
Share your thoughts in the comments
Similar Reads