Android Interview Questions

We are well aware that Android itself has a great scope and existence in the current IT sectors. So, applying to jobs related to Android is one of the dreams you all guys would be having in your heads. To crack your dream companies for the role of an android, you shall be well aware of many concepts and should practice for the interviews. To make your task easy, we have developed a set of interview questions to help you crack your android interviews.

Android Interview Questions

Q1 What are Services, and how is it different from Broadcast Receivers?

Ans. Services are the processes that run in the application’s background and don’t require any user interface to interact with. It doesn’t matter if the application is running or not; the service created by that application may still exist. (running as a background process)

Broadcast receivers are used to receive intents from other applications or systems and then notify the user. Services keep on running continuously until and unless stopped abruptly. At the same time, Broadcast Receivers are triggered only when they receive a particular intent from an application or the system.

For example, while playing music on your device, we use the services, whereas whenever the device charge falls below a limit, the broadcast receiver is triggered.

Q2. Briefly explain the view that we use to seek the user’s textual input.

Ans. To take textual inputs from the user, we use the EditText view. EditText is a view that allows users to enter any kind of textual input. Whether it’s taking input as a phone number, email address, name, or even OTPs, we use EditTexts. Below is an example of how you can declare and implement EditText in Android.

Code: XML File

<EditText
android:id = “@+id/TechVidvanEditText”
android:hint = “Enter your Email”
/>

Code: Activity File

setContentView(R.layout.activity_main)
edit_text_var = findViewByID(R.id.TechVidvanEditText)

Q3. Which language do we use to design android layouts and give a basic syntax to create a TextView using that language?

Ans. XML(Extensible Markup Language) is the language that we often use to design our android layouts. XML also allows us to transfer data from our database to our designed layouts. Now to create a TextView using XML, you can use the following code.

<TextView
android:id = “@+id/TechVidvanTextView”
android:text = “XML Text View”
//provide other attributes here
/>

Q4. Explain the features of using Linux Kernel in Android?

Ans. Some of the following are features of using Linux Kernel in Android.

  • Network Management: This programme provides networking assistance, routes networks, and examines the network stack.
  • User Management: Linux allows users to interact with the device by handling several forms of user authentication.
  • Process Management: It supervises all processes and determines when they should begin, halt, or end.
  • File Management: It governs the memory and file systems, as well as the storage and retrieval of user data.
  • Driver Management: The Linux kernel is in charge of all of the hardware’s drivers. It allows us to interface with our device’s hardware.
  • Security: Before granting access to a user, Linux verifies their identity; it also checks for safety and ensures that other users cannot access or alter your data.
  • Portability: Because Linux is supported by a wide range of devices, it allows many devices to exchange resources and data. Almost any piece of hardware can communicate with Linux

Q5. Briefly describe each of the components present in Android Architecture.

Ans. Android architecture is usually subdivided into five broad components, namely:

  • Linux Kernel
  • Libraries
  • Android Runtime
  • Application Framework
  • Applications

Linux Kernel: The Linux Kernel contains all of the low-level device drivers, such as Audio Driver, Wi-Fi Driver, Camera Driver, and so on.

Libraries: For uses such as android development, there are numerous libraries that provide varied functions. The majority of these libraries are developed in C/C++. It offers us with an environment in which we can run and debug our Android applications.

Application Framework: It contains a large number of Java-based modules.
Applications: The applications are at the top of the architectural hierarchy. System or user applications, as well as OEM manufacturer applications, are all possible.

Q6. What role does the WebKit library play in Android?

Ans. The WebKit library plays a pretty important role in Android architecture. WebKit is a part of the library and is used to render, parse, encrypt or decrypt any kind of HTML data.

Q7. State about Activity and its types in Android.

Ans. Activity is the screen using which the user interacts with the application. Activity is designed using XML code and acts as a container to hold several kinds of UI elements.

Activity is of two types:

  • Main Activity: The main activity is the one that loads initially when the programme is launched.
  • Child(or Minor) Activity: This activity can be accessed via the primary activity or from other minor activities.

Q8. Explain Activity Lifecycle with an easy example.

Ans. Activity lifecycle describes the states through which any activity goes through. Every activity has its own activity lifecycle. There are several states through which activity goes through, namely.

  • Running State,
  • Paused State,
  • Resumed State,
  • Stopped State

Now, let’s understand these by example. Suppose we are operating an application like Zomato. When we open the app and start entering the phone number to log in, that State is termed as Running State. Now suppose while entering the OTP, we are waiting for the OTP to come. In such a scenario, we are not interacting with the app. Until that time, the app was in Paused State. Now when you receive the OTP and start entering it, then the State is a Resumed State.

Many times we do multitasking like shifting from one application to another. In our case, suppose if we shift from Zomato to Whatsapp for some time, then it is the stopped State. Now, in the end, if you remove your application from your recent apps or close the application, then the activity is destroyed.

Q9. Briefly explain how applications share data among themselves in Android.

Ans. In Android, we have content providers that help us in sharing data among the applications. Firstly, the content provider establishes a connection between the applications through which they can share data. Now, we use a ContentResolver object to get the data from the established content provider.

ContentResolver takes queries from another object known as CursorLoader, which allows users to send their queries. Based on the user’s query, the data is fetched from the content provider.

A good example of a content provider is your contacts application. Suppose we are building a chat application where we need to fetch the contacts who are registered in our application. Then in such a case, we can use the content providers to access the registered user’s data from the contact list.

Q10. Explain the possible ways to search for a fragment in a given activity.

Ans. Fragments attach with any activity we wish it to attach with. Now, before attaching that fragment, we actually need to know where the fragment and to locate it, we can use the following:

  • By ID: We may use this to locate a fragment based on its ID. In this situation, you must utilise the findFragmentByID() function.
  • By Tag: We may use this to locate a fragment based on its name. In this instance, you must utilise the findFragmentByName() function.
  • By Pager: We may use this to locate a fragment depending on the view pager on which it is registered. In this case, you must use the getRegisteredFragment() method.

Q11. Which type of intent do we use to move from one activity to another? Explain with an example.

Ans. We use the explicit intent to move from one activity to another. Here we need to specify the component name which we wish to access when the intent is triggered. So, in the given scenario, we use the activity name as our component name.

For example, we can use the code below to move from the current activity to the new one.

Code:

var intent = Intent(this, YourNewActivity:: class.java)
startActivity(intent)

Q12. Describe the different ways to register for an event on Android.

Ans. There are many possible events that can occur in Android. Some of them are clicks, long presses, touches, focus change, keypresses, etc. Now, based on these events, we can provide a specific output in return to the user. To do so, we need to register the event with its respective listener. Event Registration simply means registering a listener to its respective event handler.

You can use the following steps in order to register your view with an event listener.

  • To begin, you may use the activity’s XML file to register the event listeners directly. For example, we can now use the onClick property to register an event listener in buttons.
  • The event listener may be registered by including it in an Activity class that extends the Listener Class’s attributes.
  • The last technique is to set the element’s listener dynamically.

Q13. How can a Fragment communicate with other Fragments?

Ans. As we know fragment is a part of the activity, and its existence is solely dependent on the activity itself. If a fragment requires communication with another fragment, it requires the involvement of activity in it. The two possible ways through which fragments can communicate with the other fragments are as follows:

1. Interface: You may link several pieces using an interface. In your initial fragment, all you have to do is construct an interface. You must now include the defined interface into your activity. You may easily link the interface by calling the other fragment from your activity.

2. View Model: When we need to share data or interact amongst fragments, we may establish a standard view model. Multiple pieces can interact and communicate using the view model.

Q14. Explain the stages of Android Drag and Drop.

Ans. We can notice four stages in Android Drag and Drop. These are: started, continuing, dropped, and ended. Whenever we start dragging an element from one view to another, we are actually in the starting state. The continuing state means like the dragging is in the process and the element is not yet released. The dropped state means that you have dropped the element into the desired view, and soon after this, the drag event is termed to come in a state known as ended.

Q15. Explain any four types of notifications that are present in Android.

Ans. Android comes up with several types of notifications that are used based on our needs and our application user’s demands. Some of them are:

1. Context-Generated Notifications –

Context-Generated Notifications help us to seek permissions from users. This type of notification is used in location-based applications.

2. System-Generated Notifications –

The system generates the system-generated notifications to draw the user’s attention towards an important system update, feature, or error.

3. User’s Action based Notifications –

User’s Action based notifications are the notifications that come up with a feature for the user to respond or react through the notification itself directly. One good example is your WhatsApp, where you can reply to the messages directly from the notification itself.

4. Push Notifications –

Push Notifications are the notifications that are sent from Cloud or other internet services as and when required. Push notifications help the app developers to update their users about new product launches, sales, premium offer coupons, and other marketing stuff.

Q16. What is geocoder in android? Explain with an example.

Ans. Geocoder is a kind of module that helps convert latitude and longitude to human-readable addresses and vice versa. For example, suppose I want to converse with a person who only knows French but not English. Now I am a person who only knows English and not French.

Then in such a case, I need a translator who can convert my English to French and his French to English. So similarly, in location-based services, we require a translator that can convert given latitude longitude to human-readable addresses and vice versa.

Q17. Explain the difference between forward and reverse geocoding.

Ans. Forward Geocoding is a type of geocoder that converts human-readable addresses to latitude and longitude. At the same time, reverse geocoding is a type of geocoder that converts the given latitude longitude into a human-readable address.

Q18. What are the possible intent actions that help us to place calls using Android?

Ans. We need to use either ACTION_CALL or ACTION_DIAL to make a call using Android. Below are examples of doing the same.

For example,

Code:

val callIntent = Intent(Intent.ACTION_CALL)

Code:

val callIntent = Intent(Intent.ACTION_DIAL)

Q19. What do you mean by “Tween Animation” in Android?

Ans. Tween Animation is a technique for making your layout’s designs more appealing and dynamic. Tween Animation is generally used on the layout’s view components. The UI element can be rotated, scaled, shifted, translated, or zoomed. It may be used for any element.

You’ll need to give parameters like size, duration, value, timings, and so on to add animation to your UI components. Finally, you must use the loadAnimation() function from the Animation Utils class to implement the animation in your layout.

Q20. Briefly explain the clipboard framework.

Ans. The Clipboard framework includes the following:

1. Clipboard Manager: The Clipboard Manager class maintains the system clipboard and saves and transmits data to and from it.

2. ClipData: is an object that contains the actual data item as well as its description.

3. ClipData.Item: is a ClipData object that is used to hold the actual data item, which can be text, a URI, or an intent.

4. ClipDescription: The ClipDescription object helps us in keeping track of the data’s description and even keeps it in the clipboard along with the item.

5. ClipData Methods: ClipData methods are used to produce and manipulate ClipData

Q21. What are the different types of Adapters that are present in Android?

Ans. In Android, we have six types of adapters available to us. These are,

1. BaseAdapter – The parent adapter of all accessible adapters is BaseAdapter.

2. CursorAdapter – The CursorAdapter allows you to rapidly and effectively bind data values.

3. ArrayAdapter – This ArrayAdapter assists to transport data in the form of an array, which is subsequently used to insert data into the displaying view element.

4. Custom ArrayAdapter – Custom Array Adapter assists you to tailor the kind of array to your own requirements. You may even make your own ArrayAdapter using Modal classes.

5. SimpleAdapter – You may use SimpleAdapter to maintain static data from XML in your views.

6. Custom SimpleAdapter – You may modify the data item views and offer access to each item using the custom SimpleAdapter.

Q22. Differentiate between Preferences and Shared Preferences.

Ans. You can find the below table, which distinguishes between Preferences and Shared Preferences.

Preferences Shared Preferences
Data that we store using Preference uses an implementation-dependent backing technique. Data stored in Shared Preferences uses the XML file. 
The data stored in a preference is not volatile and is secured. When the device restarts then also you can locate your data as it is in the preference. The data stored in SharedPreferences is volatile and not so secure. When you reboot your device then the data may be subject to loss or gets altered.
Preferences are very well suited when you are dealing with highly subtle information or data. When you are dealing with highly subtle information or data then you shouldn’t use SharedPreferences.
You can create preference object by using the following code:

preferencesObject = getPreferences(“YOUR_FILE_NAME”, MODE_PRIVATE)

You can create SharedPreferences object by using the following code:

sharedPreferencesObject = getSharedPreferences(“YOUR_FILE_NAME”, MODE_PRIVATE)

Q23. How can you differentiate a view from a view group in Android?

Ans. The view is like a simple fundamental UI element that is responsible for interacting with users. The view extends properties from the android.view.View class. Some of the common views are Buttons, TextViews, ImageViews, etc.

ViewGroup, on the other hand, is like a container that can hold several views and view groups inside it. ViewGroup extends properties from the android.view.ViewGroup class. Some common examples of ViewGroups are LinearLayout, RelativeLayout, etc.

Q24. Briefly explain one of the techniques using which Android maintains security for its users.

Ans. One such technique using which Android maintains security for its users is security patches. Security patches are critical in Android since they assist in ensuring the device’s security and safety. The following are some of the reasons why Android security fixes are important:

  • To fix vulnerabilities and problems with programmes, security patches are required.
  • Patches for security flaws and threats aid in the protection of our gadgets.
  • Patches for security issues improve performance and security.
  • Patches prevent hackers from gaining unauthorised access to your device or application.
  • Users’ privacy is protected through security patches, which safeguard your device and user data.

Q25. In your program, how do you locate a view element?

Ans.
findviewbyId() is a method used for finding a view identified by the ID attribute in the XML.

So, first of all, you need to provide an id to your view element, and then in your Kotlin class, you need to use the findViewById() method to bind the view element with a Kotlin class variable.

XML Code:

<TextView
android:id=”@+id/title”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”TechVidvan Android Find View”
android:textSize=”40sp”
android:textColor=”#078A0D”
android:textStyle=”bold”
android:gravity=”center”
android:layout_margin=”15dp”
/>

Kotlin Code:

lateinit var yourTextView:TextView

yourTextView = findViewById(R.id.TEXT_VIEW)

Q26. How does a Progress Bar help us in developing android applications?

Ans. As we know, Progress bars help us display the progress of currently running tasks to our users. A progress bar is a type of UI element that assists in scenarios like showing the progress of downloading a file, uploading a file, sending a file, updating some data, etc.

Consider a scenario where people have clicked on the file to download and are not aware how much more they should wait for the download to finish? This kind of situation puts a wrong impression of our application in front of our users. So, to save ourselves from those situations, we use Progress bars in our applications.

To create a Progress bar we use the following:

<ProgressBar
android:id=”@+id/your_prog_bar”
style=”?android:attr/progressBarStyleHorizontal”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:max=”100”
android:progress=”0″ />

Q27. In Android, is it possible to design user interfaces that are supported by almost all screen sizes? If yes, then how?

Ans. Android comes up with the feature to design your layouts using XML. There are several layouts that Android provides to its developers. Using these layouts, we can make our designs flexible to support all screen variants. The most common layout that is currently trending is the ConstraintLayout.

In ConstraintLayout, you can design your layout easily, and these layouts are usually supportive on most screen sizes. In ConstraintLayout, we typically add restrictions to the elements. The elements are restricted either to the parent layout or other elements.

We also have something known as RelativeLayout, using which we can place elements relative to each other. Several other layout designs like LinearLayout, TableLayout, etc. that help in designing layouts for various designs.

Along with this all, in Android Studio specifically, we get a feature to see our designed layouts view in various screen sizes. Suppose we are planning our application both for mobile and for tablets, then we can see how it appears on both the screen sizes using Android Studio.

Q28. Briefly explain some of the tools that are present in the Android Software Development Kit (SDK).

Ans. Several tools are present in the Android Software Development Kit. Some of the SDK tools are described below:

1. Proguard – The Proguard tool helps us in shrinking and optimizing the source code of the application.

2. mksdcard – It helps you in creating a disk image of the SD card that we can use with the emulator.

3. sqlite3 – It helps in accessing records that are stored by our application in the SQLite database.

4. ddms – Ddms is the tool that helps you in debugging and testing your applications.

5. emulator – The emulator is a software representation of the actual physical device and helps us run and test our build applications.

Q29. What is the role of the Manifest file in android, and what information does it store in it?

Ans. Android has a file known as AndroidManifest.xml, which consists of your application’s major and minor details. It consists of your:

  • Application Name,
  • Application Logo,
  • Activity declarations,
  • Permissions,
  • Services declarations,
  • BroadcastReceivers declarations,
  • Intent Filters, etc

The Manifest file is a core file for any android application, and without this file, your Gradle won’t build the application. The information that is stored in the Manifest file is pretty essential when the application is being installed. Your device uses this information to install the application correctly and uses it to seek permissions from the user.

Q30. How and where can we test the built android application if we don’t have an android device with us?

Ans. It’s not a point to worry if we don’t have an Android device to test our applications. We can still try our applications on some Android emulators.

Android emulators are like a software representation of an actual physical android device. Android emulators help us in testing our developed applications.
Moreover, you can customize these emulators based on your needs. Several android emulators are present in the market, like BlueStacks, GennyMotion, Phoenix OS, and Remix OS. To do so, we simply need to install that emulator on our desktop and then execute our APK file on it.

The other idea is to use Android Virtual Device, which comes along with Android Studio. Here, you don’t even need to go out of the development framework to test your applications. You can simply run your applications on Android Virtual Device.

Summary

Through this article, you came across several interview questions on android. The questions were more or less direct and were easy for you to answer. No worries if you weren’t able to recall some of them. You can revise those concepts back and come back here and try those questions again. I hope you enjoyed and found these questions helpful for you in preparing for your interviews.