Interview Questions Android
Interview Questions Android
Android is an open-sourced operating system that is used on mobile devices, such as mobiles and tablets. The
Android application executes within its own process and its own instance of Dalvik Virtual Machine(DVM) or
Android RunTime(ART).
Android architecture refers to the various layers in the Android stack. It consists of operating systems,
middleware, and applications. Each layer in the Android architecture gives different services to the layer just
above it.
Linux Kernel - It is responsible for device drivers, device management, memory management, power
management, and resource access.
Libraries - There are a set of libraries having open-source Web browser engine WebKit, well-known
library libc, libraries to play and record audio and video, SQLite database for sharing of application data
and storage, SSL libraries for internet security, etc.
Android Runtime - There are core libraries along with DVM (Dalvik Virtual Machine) or ART(Android
RunTime) as runtime which is helpful for running an Android application. DVM is optimized for mobile
devices. DVM provides fast performance and consumes less memory. Replacing DVM, ART(Android
RunTime) virtual machine was introduced to execute android apps from Android lollipop 5.0 version
(API level 21).
Android Framework - It consists of Android APIs like UI (User Interface), resources, content providers
(data), locations, telephony, and package managers. It provides interfaces and classes for the
development of Android applications.
Android Applications - Applications like home, games, contacts, settings, browsers, etc. uses the
Android framework that will make use of Android runtime and libraries.
Android
Architecture
3. List the languages used to build Android.
The most popular programming languages that can be used to develop applications in Android are:
Java: It has always been a starting point for new developers and used by the majority of people who
work with Android development. Eclipse, NetBeans, and IntelliJ IDE are the most popular
IDE’s(Integrated Development Environment) used for developing an Android application using java.
Kotlin: Kotlin is a relatively new, modern, safe, and object-oriented cross-platform programming
language used in developing an Android application. IDE’s used with kotlin are Android studio, Eclipse
IDE, etc.
C#: Developers can build native iOS and Android mobile applications by using the C# language. Visual
Studio is the best tool for developing an Android application using C#.
Python: It is a dynamic and object-oriented programming language. It is very popular in machine
learning. Pydroid 3, Dcoder, spck code editor is some of the code editors for Python.
Other languages which can be used in Android development are C++, HTML 5. C4droid, CppDroid,
AIDE, etc. are IDE’s for C++. Acode, spck code editor, etc. are examples of IDE’s used with HTML.
4. What is an activity?
Activity in java is a single screen that represents GUI(Graphical User Interface) with which users can interact in
order to do something like dial the phone, view email, etc.
For example, the Facebook start page where you enter your email/phone number and password to log in acts as
an activity.
Service is an application component that facilitates an application to run in the background in order to perform
long-running operations without user interaction. A service can run continuously in the background even if the
application is closed or even after the user switches to another application.
Activities can be terminated or closed anytime the user wishes. On the other hand, services are designed to run
in the background, and they can act independently.
Most of the services run continuously, irrespective of whether there are certain or no activities being executed.
Activities Services
They are designed to run in the These are mainly designed to run in the background. Foreground services
foreground. are also available.
Used when the user interface is
Used when the user interface is not necessary.
necessary.
They are dependent. They act independently.
7. What is Google Android SDK? Which are the tools placed in Android SDK?
The Google Android SDK is a toolset used by developers to write applications on Android-enabled devices.
Bundles are used to pass the required data between various Android activities. These are like HashMap that can
take trivial data types. Below code shows how to transfer a piece of data by using bundle:
An adapter in Android acts as a bridge between an AdapterView and the underlying data for that view. The
adapter holds the data and sends the data to the adapter view, the view can take the data from the adapter view
and shows the data on different views like a spinner, list view, grid view, etc.
AAPT stands for Android Asset Packaging Tool. It is a build tool that gives the ability to developers to view,
create, and update ZIP-compatible archives (zip, jar, and apk). It parses, indexes, and compiles the resources
into a binary format that is optimized for the platform of Android.
Portable Wi-Fi Hotspot permits you to share your mobile internet connection with other wireless devices. For
example, using your Android phone as a Wi-Fi hotspot, you can use your laptop to connect to the internet using
that access point.
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.
DDMS(Dalvik Debug Monitor Server) is a debugging tool in the Android platform. It gives the following list of
debugging features:
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)
OnCreate(): It is called when activity is created. Using this, the views are created and data is collected
from bundles.
OnStart(): It is called if the activity is becoming visible to the user. It may be succeeded by onResume()
if the activity comes to the foreground, or onStop() if it becomes hidden.
OnResume(): It is called when the activity will start an interaction with the user.
OnPause(): This is called when the activity is moving to the background but hasn’t been killed yet.
OnStop(): This is called when an activity is no longer visible to the user.
OnDestroy(): This is called when the activity is finished or destroyed.
OnRestart(): This is called after the activity has been stopped, prior to it being started again.
Life Cycle of 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.
AlertDialog:
o The AlertDialog supports 0-3 buttons, along with a list of selectable items such as checkboxes
and radio buttons.
o It is used when you want to ask the user about taking a decision between yes or no in response to
any particular action taken by the user, by remaining in the same activity and without changing
the screen.
DatePickerDialog:
o It is used for selecting the date by the user.
TimePickerDialog:
o Used for selecting the time by the user.
ProgressDialog:
o It is an extension of the AlertDialog and is used to display a progress bar. It also supports the
addition of buttons.
o This class was deprecated in API level 26 because it prevents the user from interacting with the
application. Instead of this class, we can use a progress indicator such as ProgressBar, which can
be embedded in the user interface of your application.
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:
o Providing a unique name to the java package.
o Describing various components of the application such as activity, services, and many more.
o Defining the classes which will implement these components.
An intent is a messaging object that is used to request an action from other components of an application. It can
also be used to launch an activity, send SMS, send an email, display a web page, etc.
It shows notification messages to the user from within an Android-enabled device. It alerts the user of a
particular state that occurred. There are two types of intents in Android:
20. Mention the difference between class, file and activity in Android?
Class is a compiled form of a .java file that Android uses to produce an executable .apk file.
A file is a block of arbitrary information or resources used for storing information. It can be of any file
type.
Activity is a single screen that represents GUI(Graphical User Interface) with which users can interact in
order to do something like dial the phone, view email, etc.
Toast is a message that pops up on the screen. It is used to display the message regarding the status of the
operation initiated by the user and covers only the expanse of space required for the message while the user’s
recent activity remains visible and interactive.
Toast notification automatically fades in and out and it does not accept interaction events.
Syntax:
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.
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:
Types of Context
The difference between the implicit and explicit Intents are given below:
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,
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,
24. 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:
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
IntentService.
25. What are the troubleshooting techniques you can follow if an application is crashing
frequently?
If an Android application is crashing frequently, you can follow the below-given techniques:
Compatibility Check:
It is not possible to test an application for all kinds of devices and operating systems. There might be a
possibility that an application is not compatible with your OS.
Memory Management:
Some apps run perfectly on one mobile device but might crash on other devices. This is where
processing power, memory management, and CPU speed are considered.
As there is a limited amount of memory space on mobile devices, you can free up memory space for the
application to function properly.
If an application is frequently crashing, you can delete the application’s data, which will clear its cache
memory and allow some free space on your device and might boost the app’s performance.
Standard:
This launch mode generates an activity’s new instance in the task from which it originated.
It is possible to create several instances for the same activity.
For Example, suppose our current stack is A -> B -> C. Now, if we launch activity B again with the
“standard” launch mode, then the new stack will be A -> B -> C -> B.
SingleTop:
This launch mode is similar to the Standard launch mode except if there exists an activity’s previous
instance on the top of the stack, then a new instance will not be created.
But the intent will be sent to the activity’s existing instance.
For example, suppose our current stack is A -> B -> C. Now, if we launch the activity B again with
“singleTop” launch mode,then the new stack will be A -> B -> C -> B.
Consider another example, where the current stack is A -> B -> C. Now, if we launch activity C again
with the “singleTop” launch mode, then the stack will remain the same i.e., A -> B -> C. The intent will
be passed to the onNewIntent() method.
SingleTask:
This launch mode will create a new task and push a new instance to the task as the root.
For example, suppose our current stack is A -> B -> C -> D. Now, if we launch activity B again with the
“singleTask” launch mode, then the new stack will be A -> B. Here, a callback has been received on the
old instance and C and D activities are destroyed.
SingleInstance:
This launch mode is similar to the SingleTask launch mode. But the system doesn’t support launching
any new activities in the same task.
In a situation where the new activity is launched, it is launched in a separate task.
For example, Suppose our current stack is A -> B -> C. Now, if we launch the activity D with the
“singleInstance” launch mode, then there will be two stacks:
o A -> B -> C
o D, If you call activity E, then it will be added to the first stack.
o A -> B -> C -> E
o D
Again if you Call the activity D, then it will call the same activity from the 2nd stack and pass the intent to
onNewIntent().
Containers carry objects and widgets together, based on which specific items are required and in what particular
arrangement is needed. Containers may hold labels, buttons, fields, or even child containers, etc. For example, if
you want a form with fields on the left and labels on the right, you will need a container. If you want the OK
and Cancel buttons to be below the rest of the form, next to one another, and flush to the right side of the screen,
you will need a container. If you have several widgets, you will need a container to have a root element to place
the widgets inside.
Android provides a collection of view classes that serve as containers for views. These container classes are
called layouts, which are defined in the form of XML files that cannot be changed by our code during
execution. The layout managers provided by Android SDK are LinearLayout, RelativeLayout, FrameLayout,
AbsoluteLayout, GridLayout, and TableLayout.
Dalvik serves as a virtual machine, and it is responsible for running every Android application. Because of
Dalvik, a device will have the ability to execute multiple instances of virtual machines efficiently through better
memory management.
29. What is the latest version of Android? List all the versions of Android.
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.
31. Explain in detail about the important file and folders used when you create a new
Android application.
App:
It describes the basic characteristics of the application and defines each of its components.
java:
This contains the .java source files and .kt(source code written in Kotlin) source files of your project. By
default, it includes a MainActivity.java or MainActivity.kt source file.
You create all the activities which have .java and .kt extensions under this file and also it includes all the
code behind the application.
res:
It is used to store the values for the resources that are used in various Android projects to include
features of color, styles, dimensions, etc.
It is a directory for files like styles.xml, strings.xml, colors.xml, dimens.xml, etc.
Scripts:
32. What is the difference between Serializable and Parcelable? Which is the best approach in
Android?
While developing applications usually it needs to transfer data from one activity to another. This data needs to
be added into a corresponding intent object. Some additional actions are required to make the data suitable for
transfer. For doing that the object should be either serializable or parcelable.
Serializable:
Serializable is a standard Java interface. In this approach, you simply mark a class Serializable by
implementing the interface and java will automatically serialize it.
Reflection is used during the process and many additional objects are created. This leads to plenty of
garbage collection and poor performance.
Parcelable:
Parcelable is an Android-specific interface. In this approach, you implement the serialization yourself.
Reflection is not used during this process and hence no garbage is created.
Parcelable is far more efficient than Serializable since it gets around some problems with the default
Java serialization scheme. Also, it is faster because it is optimized for usage on the development of
Android, and shows better results.
33. What database is used in Android? How it is different from client-server database
management systems?
SQLite is the open-source relational database used in Android. The SQLite engine is serverless, transactional,
and also self-contained. Instead of the client-server relationship of most database management systems, the
SQLite engine is integrally linked with the application. The library can be called dynamically and it can make
use of simple function calls that reduce latency in database access.
Service Thread
Service is an application component that facilitates an application to run in the
A Thread is a concurrent unit
background in order to perform long-running operations without user
of execution.
interaction.
Google has brought in
It exposes few functionalities to other applications by calling
handlers and loopers into
Context.bindService().
threads.
When an application is killed,
When an application is killed, service is not killed.
the thread is killed.
Content provider is one of the primary building blocks of Android applications, which manages access to a
central repository of data. It acts as a standard interface that connects data in one process with code running in
another process. So it can be used to share the data between different applications.
They are responsible for encapsulating the data and providing mechanisms for defining data security. It is
implemented as a subclass of ContentProviderclass and must implement a set of APIs that will enable other
applications to perform transactions.
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.
37. What is the difference between compileSdkVersion and targetSdkVersion?
compileSdkVersion:
The compileSdkVersion is the version of API the application is compiled against. You can use Android
API features involved in that version of the API (as well as all previous versions).
For example, if you try and use API 15 features but set compileSdkVersion to 14, you will get a
compilation error. If you set compileSdkVersion to 15 you can still run the app on an API 14 device as
long as your app’s execution paths do not attempt to invoke any APIs specific to API 15.
targetSdkVersion:
The targetSdkVersion indicates that you have tested your app on (presumably up to and including) the
version you specify. This is like a certification or sign-off you are giving the Android OS as a hint to
how it should handle your application in terms of OS features.
For example, setting the targetSdkVersion value to “11” or higher permits the system to apply a new
default theme (Holo) to the application when running on Android 3.0 or higher. It also disables screen
compatibility mode when running on larger screens (because support for API level 11 implicitly
supports larger screens).
38. Explain about java classes related to the use of sensors on Android.
Android sensor API provides many classes and interface for the use of sensors on Android. The important
classes and interfaces of sensor API are given below:
Sensor class: This class helps you to create an instance of a specific sensor. It provides methods that let
you determine a sensor’s capabilities.
SensorManager class: This class is used to create an instance of the sensor service. It provides methods
to access and list sensors, to register and unregister sensor listeners, etc.
SensorEvent class: This Java class is used to create a sensor event object. It provides information about
the sensor event including raw sensor data, the accuracy of data, type of sensor, timestamp of event, etc.
SensorEventListener interface: This interface is used to create two callback methods that receive
sensor event notifications when sensor value changes or when sensor accuracy changes. Those two
methods are void onAccuracyChanged(Sensor sensor, int accuracy) which is called when
sensor accuracy is changed and
void onSensorChanged(SensorEvent event) which is called when sensor values are changed.
The JobSchedular API is used for scheduling different types of jobs against the framework that will be executed
in your app’s own process. This allows your application to perform the given task while being considerate of
the device’s battery at the cost of timing control.
The JobScheduler supports batch scheduling of jobs. The Android system can combine jobs for reducing battery
consumption. JobManager automatically handles the network unreliability so it makes handling uploads easier.
Here is some example of a situation where you would use this job scheduler:
Tasks that should be done when the device is connected to a power supply.
Tasks that require a Wi-Fi connection or network access.
Tasks should run on a regular basis as a batch where the timing is not critical.
1) What is Android?
Android is an open-source, Linux-based operating system used in mobiles, tablets, televisions, etc.
Andy Rubin.
1. Aestro
2. Blender
3. Cupcake
4. Donut
5. Eclair
6. Froyo
7. Gingerbread
8. Honeycomb
9. Ice Cream Sandwich
10. Jelly Bean
11. KitKat
12. Lollipop
13. Marshmallow
More details...
Highly optimized Virtual Machine: Android uses a highly optimized virtual machine for mobile devices,
called DVM (Dalvik Virtual Machine).
Yes, an android app can be developed in C/C++ also using android NDK (Native Development Kit). It makes
the performance faster. It should be used with Android SDK.
Activity
View
Intent
Service
Content Provider
Fragment etc.
More details...
Activity is like a frame or window in java that represents GUI. It represents one screen of android.
1. onCreate()
2. onStart()
3. onResume()
4. onPause()
5. onStop()
6. onRestart()
7. onDestroy()
More details...
1. Implicit Intent
2. Explicit Intent
An android toast provides feedback to the users about the operation being performed by them. It displays the
message regarding the status of operation initiated by the user.
AndroidManifest.xml
build.xml
bin/
src/
res/
assets/
The files which can be injected for the building up of a process are called as application resource file.
A unique Linux ID is assigned to each application in android. It is used for the tracking of a process.
17) Can the bytecode be written in java be run on android?
No
Shared Preferences
Internal Storage
External Storage
SQLite Databases
Network Connection
More details...
More details...
AAPT is an acronym for android asset packaging tool. It handles the packaging process.
The fragment is a part of Activity by which we can display multiple screens on one activity.
ADB stands for Android Debug Bridge. It is a command line tool that is used to communicate with the emulator
instance.
NDK stands for Native Development Kit. By using NDK, you can develop a part of an app using native
language such as C/C++ to boost the performance.
ANR stands for Application Not Responding. It is a dialog box that appears if the application is no longer
responding.
32) What is the Google Android SDK?
The Google Android SDK is a toolset which is used by developers to write apps on Android-enabled devices. It
contains a graphical interface that emulates an Android-driven handheld environment and allows them to test
and debug their codes.
APK is a short form stands for Android Packaging Key. It is a compressed key with classes, UI's, supportive
assets and manifest. All files are compressed to a single file is called APK.
Android applications are written by using the java (Android SDK) and C/C++ (Android NDK).
ADT stands for Android Development Tool. It is used to develop the applications and test the applications.
View Group is a collection of views and other child views. It is an invisible part and the base class for layouts.
An adapter is used to create a child view to present the parent view items.
We can change bitmap images into nine sections with four corners, four edges, and an axis.
Application widgets are miniature application views that can be embedded in other applications and receive
periodic updates.
FLAG_ACTIVITY_NEW_TASK
FLAG_ACTIVITY_CLEAR_TOP
A singleton class is a class which can create only an object that can be shared by all other classes.
In sleep mode, CPU is slept and doesn't accept any commands from android device except Radio interface layer
and alarm.
In Android, a drawable folder is compiled a visual resource that can use as a background, banners, icons, splash
screen, etc.
DDMS stands for Dalvik Debug Monitor Server. It gives the wide array of debugging features:
1. Linux Kernal
2. Libraries
3. Android Framework
4. Android Applications
More details...
The portable wi-fi hotspot is used to share internet connection to other wireless devices.
Alert Dialog
Progress Dialog
Date Picker Dialog
Time picker Dialog
Inflate Exception
Surface.OutOfResourceException
SurfaceHolder.BadSurfaceTypeException
WindowManager.BadTokenException
50) What are the basic tools used to develop an Android app?
JDK
Eclipse+ADT plugin
SDK Tools
Android is a Linux-based, open-sourced operating system commonly found on mobile devices, such as
smartphones and tablets. It’s a kernel-based system that gives developers the flexibility to design and deploy
simple and/or advanced apps.
The current version of Android is 9.0, also called Android Pie, and it came out in August of 2018.
3: What database is used for the Android platform?
Android Framework
Android Applications
Linux Kernel
Libraries
5: Can you change an application’s name after you have deployed it?
Although you CAN change it, the real question should be “SHOULD you”? Changing an application’s name
risks breaking some of its functionality.
JDK
SDK Tools
Eclipse+ADT Plugin
This is a set of tools that Android developers use in order to develop or write apps. It features a graphical user
interface that emulates a handheld, Android-driven environment, making it easier for developers to create, test,
and debug their code.
Android-primarily uses Java, but it also supports C/C++, which, if used with Android SDK, will run faster.
It’s a set of APIs that permits developers to create apps, and consists of:
Intent
Activities
Content Providers
Others
12: What’s an intent in the context of Android? Describe the different types.
Much what it sounds like, it’s the intention to perform an action, a message that is passed between components.
Intents request actions from a different component, such as sending an email, opening a web page, or launch a
given activity. The two types are:
Implicit Intent
This is where the intent doesn’t define the target component, requiring the Android system to conduct an
evaluation of the components.
Explicit Intent
On the other hand, the explicit intent directly identifies the target component.
This is a broadcast using the send sticky broadcast() method. The intent sticks around after the broadcast, which
allows others to collect data from it.
These are the parts of a mobile app that a user sees and interacts with. It represents a Graphic User Interface
(GUI), representing one Android screen.
Active: The activity is at the top of the stack, running in the foreground
Paused: The activity is still visible but cannot receive user input events; it’s in the background
Stopped: The activity is invisible and consequently is paused, and obscured or hidden by a different
activity
Destroyed: The activity’s process has been killed, completed, or terminated
16: What’s a content provider?
Content providers share information between different Android applications. They allow users to access data
within an application. Examples include contact information, images, video, and audio.
Toast, in this case, is a pop-up box (hence the word) giving feedback regarding an operation that the users
initiated, informing the user of the current status of said operation. For instance, when a smartphone user sends
a message to a friend, a toast is displayed saying “sending message”.
18: What’s the difference between mobile testing and mobile application testing?
Mobile Testing is performed on the mobile device itself, specifically on the device’s features like Contacts,
SMS, the browsers, and it’s Calling function. Mobile Application Testing tests the features and functions of the
apps loaded onto a mobile device.
Android’s weaknesses stem from one of its advantages, namely that it’s everywhere and can run on a huge
number of devices.
First of all, developers can encounter difficulty in creating apps that easily adjust the display to
accommodate the widely disparate screen sizes of all these different devices.
Secondly, the large number of devices has given rise to a large number of custom-made Android
versions to suit them, thus there is no central set of policies governing upgrades, or parameters for
running on many operating systems. It’s anarchy out there!
No, it cannot.
This is an acronym for Android Asset Packaging Tool. The tool gives developers the ability to deal with zip-
compatible archives, including content viewing, creation, and extraction.
This acronym stands for Android Debug Bridge (a tool found in SDK). It’s a command-line tool used to
communicate between the emulator instances.
25: What does APK mean?
It’s short for Android Packaging Kit. Every file in the Android packaging key is compressed into a single file,
the APK.
This is an acronym for Application Not Responding, a pop-up or notification that kicks in when the application
is experiencing lag time for the user due to too many functions being performed simultaneously.
27: How do you place layouts in Android? Where are they placed?
Exceptions include:
Inflate Exception
Surface.OutOfResourceException
SurfaceHolder.BadSurfaceTypeException
WindowManager.BadTokenException
29: What are the four essential items in every Android project?
AndroidManifest.xml
build.xml
bin/
src/
res/
assets/
Alert Dialog: Features selectable elements such as radio buttons and/or checkboxes
Progress Dialog: Shows progress, either via a progress wheel or bar
Date Picker Dialog: Lets the user select a date
Time picker Dialog: Lets the user select a time
31: An Android application keeps crashing. How do you resolve the issue?
When an application crashes often, these are the best ways to fix it -
1. It could be a memory space issue. Make sure there’s enough memory space.
2. Clear the app data by clearing the cache memory using “settings” under Application Manager.
3. Not all apps run the same on assorted machines, so you may have to tinker with memory management.
4. It may be a matter of compatibility; a problem that can be headed off by testing the app on as many of
your devices as possible beforehand.
1) What is Android?
It is an open-sourced operating system that is used primarily on mobile devices, such as cell phones and tablets.
It is a Linux kernel-based system that’s been equipped with rich components that allows developers to create
and run apps that can perform both basic and advanced functions.
The Google Android SDK is a toolset that developers need in order to write apps on Android enabled devices. It
contains a graphical interface that emulates an Android driven handheld environment, allowing them to test and
debug their codes.
Linux Kernel
Libraries
Android Framework
Android Applications
The Android Framework is an important aspect of the Android Architecture. Here you can find all the classes
and methods that developers would need in order to write applications on the Android environment.
5) What is AAPT?
AAPT is short for Android Asset Packaging Tool. This tool provides developers with the ability to deal with
zip-compatible archives, which includes creating, extracting as well as viewing its contents.
The emulator lets developers “play” around an interface that acts as if it were an actual mobile device. They can
write and test codes, and even debug. Emulators are a safe place for testing codes especially if it is in the early
design phase.
8) Describe Activities.
Activities are what you refer to as the window to a user interface. Just as you create windows in order to display
output or to ask for an input in the form of dialog boxes, activities play the same role, though it may not always
be in the form of a user interface.
Intents displays notification messages to the user from within the Android enabled device. It can be used to alert
the user of a particular state that occurred. Users can be made to respond to intents.
Activities can be closed, or terminated anytime the user wishes. On the other hand, services are designed to run
behind the scenes, and can act independently. Most services run continuously, regardless of whether there are
certain or no activities being executed.
These are the essential items that are present each time an Android project is created:
AndroidManifest.xml
build.xml
bin/
src/
res/
assets/
The use of XML-based layouts provides a consistent and somewhat standard means of setting GUI definition
format. In common practice, layout details are placed in XML files while other items are placed in source files.
Orientation, which can be set using setOrientation(), dictates if the LinearLayout is represented as a row or as a
column. Values are set as either HORIZONTAL or VERTICAL.
Developers can write and register apps that will specifically run under the Android environment. This means
that every mobile device that is Android enabled will be able to support and run these apps. With the growing
popularity of Android mobile devices, developers can take advantage of this trend by creating and uploading
their apps on the Android Market for distribution to anyone who wants to download it.
Given that Android is an open-source platform, and the fact that different Android operating systems have been
released on different mobile devices, there’s no clear cut policy to how applications can adapt with various OS
versions and upgrades. One app that runs on this particular version of Android OS may or may not run on
another version. Another disadvantage is that since mobile devices such as phones and tabs come in different
sizes and forms, it poses a challenge for developers to create apps that can adjust correctly to the right screen
size and other varying features and specs.
Adb is short for Android Debug Bridge. It allows developers the power to execute remote shell commands. Its
basic function is to allow and control communication towards and from the emulator port.
20) Which elements can occur only once and must be present?
Among the different elements, the “and” elements must be present and can occur only once. The rest are
optional, which can occur as many times as needed.
Escape characters are preceded by double backslashes. For example, a newline character is created using ‘\\n’
Permissions allow certain restrictions to be imposed primarily to protect data and code. Without these, codes
could be compromised, resulting to defects in functionality.
Because every component needs to indicate which intents they can respond to, intent filters are used to filter out
intents that these components are willing to receive. One or more intent filters are possible, depending on the
services and activities that is going to make use of it.
A call to onStop method happens when an activity is no longer visible to the user, either because another
activity has taken over or if in front of that activity.
26) Is there a case wherein other qualifiers in multiple resources take precedence over locale?
Yes, there are actually instances wherein some qualifiers can take precedence over locale. There are two known
exceptions, which are the MCC (mobile country code) and MNC (mobile network code) qualifiers.
foreground activity
visible activity
background activity
empty process
One technique that prevents the Android system from concluding a code that has been responsive for a long
period of time is to create a child thread. Within the child thread, most of the actual workings of the codes can
be placed, so that the main thread runs with minimal periods of unresponsive times.
Dalvik serves as a virtual machine, and it is where every Android application runs. Through Dalvik, a device is
able to execute multiple virtual machines efficiently through better memory management.
This file is essential in every application. It is declared in the root directory and contains information about the
application that the Android system must know before the codes can be executed.
31) What is the proper way of setting up an Android-powered device for app development?
The following are steps to be followed prior to actual application development in an Android-powered device:
When default resources, which contain default strings and files, are not present, an error will occur and the app
will not run. Resources are placed in specially named subdirectories under the project res/ directory.
34) When dealing with multiple resources, which one takes precedence?
Assuming that all of these multiple resources are able to match the configuration of a device, the ‘locale’
qualifier almost always takes the highest precedence over the others.
The ANR dialog is displayed to the user based on two possible conditions. One is when there is no response to
an input event within 5 seconds, and the other is when a broadcast receiver is not done executing within 10
seconds.
AIDL, or Android Interface Definition Language, handles the interface requirements between a client and a
service so both can communicate at the same level through interprocess communication or IPC. This process
involves breaking down objects into primitives that Android can understand. This part is required simply
because a process cannot access the memory of the other process.
-string
-charSequence
-List
-Map
-all native Java data types like int,long, char and Boolean
A visible activity is one that sits behind a foreground dialog. It is actually visible to the user, but not necessarily
being in the foreground itself.
The foreground activity, being the most important among the other states, is only killed or terminated as a last
resort, especially if it is already consuming too much memory. When a memory paging state has been reach by
a foreground activity, then it is killed so that the user interface can retain its responsiveness to the user.
Yes, it is possible to do that, such as when you want to create a background behavior for a particular activity.
You can do this by using add(Fragment,string) method to add a fragment from the activity.
42) How do you remove icons and widgets from the main screen of the Android device?
To remove an icon or shortcut, press and hold that icon. You then drag it downwards to the lower part of the
screen where a remove button appears.
43) What are the core components under the Android application architecture?
– services
– intent
– resource externalization
– notifications
– content providers
A project under Android development, upon compilation, becomes an .apk file. This apk file format is actually
made up of the AndroidManifest.xml file, application code, resource files, and other related files.
45) What is a Sticky Intent?
A Sticky Intent is a broadcast from sendStickyBroadcast() method such that the intent floats around even after
the broadcast, allowing others to collect data from it.
46) Do all mobile phones support the latest Android operating system?
Some Android-powered phone allows you to upgrade to the higher Android operating system version. However,
not all upgrades would allow you to get the latest version. It depends largely on the capability and specs of the
phone, whether it can support the newer features available under the latest Android version.
Portable Wi-Fi Hotspot allows you to share your mobile internet connection to other wireless device. For
example, using your Android-powered phone as a Wi-Fi Hotspot, you can use your laptop to connect to the
Internet using that access point.
In Android development, an action is what the intent sender wants to do or expected to get as a response. Most
application functionality is based on the intended action.
49) What is the difference between a regular bitmap and a nine-patch image?
In general, a Nine-patch image allows resizing that can be used as background or other image size requirements
for the target device. The Nine-patch refers to the way you can resize the image: 4 corners that are unscaled, 4
edges that are scaled in 1 axis, and the middle one that can be scaled into both axes.
The main language supported is Java programming language. Java is the most popular language for app
development, which makes it ideal even for new Android developers to quickly learn to create and deploy
applications in the Android environment.
Base
Why is it recommended to use only the default constructor to create a Fragment? - Learn from here
What is Activity and its lifecycle?
What is the difference between onCreate() and onStart()
When only onDestroy is called for an activity without onPause() and onStop()? - Learn from here
Why do we need to call setContentView() in onCreate() of Activity class? - Learn from here
What is onSavedInstanceState() and onRestoreInstanceState() in activity?
o onSavedInstanceState() - This method is used to store data before pausing the activity.
o onRestoreInstanceState() - This method is used to recover the saved state of an activity when the
activity is recreated after destruction. So, the onRestoreInstanceState() receive the bundle that contains
the instance state information.
What is Fragment and its lifecycle.
What are "launchMode"? - Learn from here and singleTask launchMode in Android
What is the difference between a Fragment and an Activity? Explain the relationship between the
two. - Learn from here
When should you use a Fragment rather than an Activity?
o When you have some UI components to be used across various activities
o When multiple view can be displayed side by side just like viewPager
What is the difference between FragmentPagerAdapter vs FragmentStatePagerAdapter?
o FragmentPagerAdapter: Each fragment visited by the user will be stored in the memory but the view will
be destroyed. When the page is revisited, then the view will be created not the instance of the
fragment.
o FragmentStatePagerAdapter: Here, the fragment instance will be destroyed when it is not visible to the
user, except the saved state of the fragment.
What is the difference between adding/replacing fragment in backstack? - Learn from here
How would you communicate between two Fragments?
What is retained Fragment?
o By default, Fragments are destroyed and recreated along with their parent Activity’s when a
configuration change occurs. Calling setRetainInstance(true) allows us to bypass this destroy-and-
recreate cycle, signaling the system to retain the current instance of the fragment when the activity is
recreated.
What is the purpose of addToBackStack() while commiting fragment transaction?
o By calling addToBackStack(), the replace transaction is saved to the back stack so the user can reverse
the transaction and bring back the previous fragment by pressing the Back button. For more Learn from
here
What is the difference between ListView and RecyclerView? - Learn from here
How does RecyclerView work internally?
What is the ViewHolder pattern? Why should we use it? - Learn from here
RecyclerView Optimization - Scrolling Performance Improvement - Learn from here
Optimizing Nested RecyclerView - Learn from here
What is SnapHelper? - Learn from here: SnapHelper
What is Intent?
What is an Implicit Intent?
What is an Explicit Intent?
What is a BroadcastReceiver? - Learn from here
What is a LocalBroadcastManager?
What is the function of an IntentFilter? - Learn from here
What is a Sticky Intent?
o Sticky Intents allows communication between a function and a service. sendStickyBroadcast() performs
a sendBroadcast(Intent) known as sticky, i.e. the Intent you are sending stays around after the broadcast
is complete, so that others can quickly retrieve that data through the return value of
registerReceiver(BroadcastReceiver, IntentFilter). For example, if you take an intent for
ACTION_BATTERY_CHANGED to get battery change events: When you call registerReceiver() for that
action — even with a null BroadcastReceiver — you get the Intent that was last Broadcast for that
action. Hence, you can use this to find the state of the battery without necessarily registering for all
future state changes in the battery.
Describe how broadcasts and intents work to be able to pass messages around your app? - Learn
from here
What is a PendingIntent?
o If you want someone to perform any Intent operation at future point of time on behalf of you, then we
will use Pending Intent.
What are the different types of Broadcasts? - Learn from here
Services
Inter-process Communication
How can two distinct Android apps interact? - Learn from here
Is it possible to run an Android app in multiple processes? How? - Learn from here
What is AIDL? Enumerate the steps in creating a bounded service through AIDL. - Learn from
here
What can you use for background processing in Android? - Learn from here
What is a ContentProvider and what is it typically used for? - Learn from here and here
Long-running Operations
How to run parallel tasks in Java or Android, and get callback when all complete? - Long-running
tasks in parallel with Kotlin Flow
Why should you avoid to run non-ui code on the main thread? - Learn from here
What is ANR? How can the ANR be prevented? - Learn from here
What is an AsyncTask(Deprecated in API level 30) ?
What are the problems in AsyncTask?
When would you use java thread instead of an AsyncTask? - Learn from here
What is a Loader? (Deprecated) - Learn from here
What is the relationship between the life cycle of an AsyncTask and an Activity? What problems
can this result in? How can these problems be avoided?
o An AsyncTask is not tied to the life cycle of the Activity that contains it. So, for example, if you
start an AsyncTask inside an Activity and the user rotates the device, the Activity will be
destroyed (and a new Activity instance will be created) but the AsyncTask will not die but
instead goes on living until it completes.
o Then, when the AsyncTask does complete, rather than updating the UI of the new Activity, it
updates the former instance of the Activity (i.e., the one in which it was created but that is not
displayed anymore!). This can lead to an Exception (of the type
java.lang.IllegalArgumentException: View not attached to window manager if you use, for
instance, findViewById to retrieve a view inside the Activity).
o There’s also the potential for this to result in a memory leak since the AsyncTask maintains a
reference to the Activity, which prevents the Activity from being garbage collected as long as the
AsyncTask remains alive.
o For these reasons, using AsyncTasks for long-running background tasks is generally a bad idea .
Rather, for long-running background tasks, a different mechanism (such as a service) should be
employed.
o Note: AsyncTasks by default run on a single thread using a serial executor, meaning it has only 1
thread and each task runs one after the other.
Explain Looper, Handler and HandlerThread.
Android Memory Leak and Garbage Collection
How do you handle bitmaps in Android as it takes too much memory? - Learn from here and here
What is the difference between a regular Bitmap and a nine-patch image?
o In general, a Nine-patch image allows resizing that can be used as background or other image size
requirements for the target device. The Nine-patch refers to the way you can resize the image: 4 corners
that are unscaled, 4 edges that are scaled in 1 axis, and the middle one that can be scaled into both
axes.
Tell about the Bitmap pool. - Learn from here
How image compression is preformed?
Data Saving
What is a Spannable?
What is a SpannableString?
o A SpannableString has immutable text, but its span information is mutable. Use a SpannableString when
your text doesn't need to be changed but the styling does. Spans are ranges over the text that include
styling information like color, heighliting, italics, links, etc
What are the best practices for using text in Android?
How to implement Dark mode in any application?
How to generate dynamic colors based in image?
Explain about Density Independence Pixel
Memory Optimizations
Permissions
Native Programming
What is the NDK and why is it useful? - Learn from here: Android NDK and RenderScript
What is renderscript? - Learn from here: Android NDK and RenderScript
Android Jetpack
Others
Why Bundle class is used for data passing and why cannot we use simple Map data structure? -
Learn from here
How do you troubleshoot a crashing application? - Learn from here
Explain Android notification system? Learn from here: How does the Android notification system
work?
What is the difference between Serializable and Parcelable? Which is the best approach in
Android?
What is AAPT? - Learn from here
What is the best way to update the screen periodically? - Learn from here
FlatBuffers vs JSON.
HashMap, ArrayMap and SparseArray
What are Annotations?
How to create custom Annotation?
How to handle multi-touch in android?
What is the support library? Why was it introduced?
What is Android Data Binding?
How to check if Software keyboard is visible or not?
How to take screenshot in Android programmatically?
Android Libraries
Android Architecture
OOP
o Note: In the above syntax, the name of the constructor is the same as that of class and it has no
return type.
o Method Syntax
o public class SomeClassName{
o public void someMethodName(parameter_list){
o ...
o }
o // call method
o someMethodName(parameter_list)
}
Will output:
The most basic difference is that overloading is being done in the same class while for overriding
base and child classes are required. Overriding is all about giving a specific implementation to
the inherited method of parent class.
Static binding is being used for overloaded methods and dynamic binding is being used for
overridden/overriding methods. Performance: Overloading gives better performance compared to
overriding. The reason is that the binding of overridden methods is being done at runtime.
Private and final methods can be overloaded but they cannot be overridden. It means a class can
have more than one private/final methods of same name but a child class cannot override the
private/final methods of their base class.
Return type of method does not matter in case of method overloading, it can be same or
different. However in case of method overriding the overriding method can have more specific
return type (meaning if, for example, base method returns an instance of Number class, all
overriding methods can return any class that is extended from Number, but not a class that is
higher in the hierarchy, like, for example, Object is in this particular case).
Argument list should be different while doing method overloading. Argument list should be
same in method Overriding. It is also a good practice to annotate overridden methods with
@Override to make the compiler be able to notify you if child is, indeed, overriding parent's
class method during compile-time.
What are the access modifiers you know? What does each one do?
o There are four access modifiers in Java language (from strictest to the most lenient):
1. private variables, methods, constructors or inner classes are only visible to its' containing class
and its' methods. This modifier is most commonly used, for example, to allow variable access
only through getters and setters or to hide underlying implementation of classes that should not
be used by user and therefore maintain encapsulation. Singleton constructor is also marked
private to avoid unwanted instantiation from outside.
2. Default (no keyword is used) this modifier can be applied to classes, variables, constructors
and methods and allows access from classes and methods inside the same package.
3. protected can be used on variables, methods and constructors therefore allowing access only
to subclasses and classes that are inside the same package as protected members' class.
4. public modifier is widely-used on classes, variables, constructors and methods to grant access
from any class and method anywhere. It should not be used everywhere as it implies that data
marked with public is not sensitive and can not be used to harm the program.
Can an Interface implement another Interface?
o Yes, an interface can implement another interface (and more than one), but it needs to use extends,
rather than implements keyword. And while you can not remove methods from parent interface, you
can add new ones freely to your sub-interface.
What is Polymorphism? What about Inheritance?
o Polymorphism in Java has two types: Compile time polymorphism (static binding) and Runtime
polymorphism (dynamic binding). Method overloading is an example of static polymorphism,
while method overriding is an example of dynamic polymorphism.
An important example of polymorphism is how a parent class refers to a child class object. In
fact, any object that satisfies more than one IS-A relationship is polymorphic in nature.
For instance, let’s consider a class Animal and let Cat be a subclass of Animal. So, any cat IS
animal. Here, Cat satisfies the IS-A relationship for its own type as well as its super class
Animal.
o Inheritance can be defined as the process where one class acquires the properties (methods and
fields) of another. With the use of inheritance the information is made manageable in a
hierarchical order.
The class which inherits the properties of other is known as subclass (derived class, child class)
and the class whose properties are inherited is known as superclass (base class, parent class).
Inheritance uses the keyword extends to inherit the properties of a class. Following is the syntax
of extends keyword.
class Super {
.....
.....
}
class Sub extends Super {
.....
.....
}
Multiple inheritance in Classes and Interfaces in java
What are the design patterns?
o Creational patterns
Builder Wikipedia
Factory Wikipedia
Singleton Wikipedia
Monostate Wikipedia
Fluent Interface Pattern Wikipedia
Structural patterns
Adapter Wikipedia
Decorator Wikipedia
Facade Wikipedia
Behavioural patterns
Chain of responsibility Wikipedia
Iterator Wikipedia
Strategy Wikipedia
In a nutshell, generics enable types (classes and interfaces) to be parameters when defining
classes, interfaces and methods. Much like the more familiar formal parameters used in method
declarations, type parameters provide a way for you to re-use the same code with different
inputs. The difference is that the inputs to formal parameters are values, while the inputs to type
parameters are types. (Official Java Documentation)
And let the compiler take care of noticing, if you put some object, of type other than Integer
into this list and warn you.
o It should be noted that standard class hierarchy does not apply to generic types. It means that
Integer in List<Integer> is not inherited from <Number> - it is actually inherited directly from
<Object>. You can still put some constraints on what classes can be passed as a parameter into a
generic by using wildcards like <?>, <? extends MyCustomClass> or <? super Number>.
o While generics are very useful, late inclusion into Java language has put some restraints on their
implementation - backward compatibility required them to remain just "syntactic sugar" - they
are erased (type erasure) during compile-time and replaced with object class.
What is Java PriorityQueue? - In Priority Queue, each element is having some priority and all the
elements are present in a queue. The operations are performed based on the priority.
Objects and Primitives
Note: The String class is immutable, so that once it is created a String object cannot be changed.
The String class has a number of methods, some of which will be discussed below, that appear to
modify strings. Since strings are immutable, what these methods really do is create and return a
new string that contains the result of the operation. (Official Java Documentation)
This class is also unique in a sense, that, when you create an instance like this:
"Hello, World!" is called a literal and compiler creates a String object with its' value. So
is a valid statement, that, firstly, will create an object with literal value "Hello, World!" and then
will create and return another object with value "HELLO, WORLD!"
o String was made immutable to prevent malicious manipulation of data, when, for example, user
login or other sensitive data is being send to a server.
What does it means to say that a String is immutable?
o It means that once created, String object's char[] (its' containing value) is declared final and,
therefore, it can not be changed during runtime.
What is String.intern()? When and why should it be used?
o String.intern() is used to mange memory in Java code. It is used when we have duplicates value in
different strings. When you call the String.intern(), then if in the String pool that string is present
then the equals() method will return true and it will return that string only.
Can you list 8 primitive types in java?
o byte
o short
o int
o long
o float
o double
o char
o String
o boolean
What is the difference between an Integer and int?
o int is a primitive data type (with boolean, byte, char, short, long, float and double), while
Integer (with Boolean, Byte, Character, Short,Long, Float and Double) is a wrapper class that
encapsulates primitive data type, while providing useful methods to perform different tasks with it.
What is Autoboxing and Unboxing?
o Autoboxing and Unboxing is the process of automatic wrapping (putting in a box) and unwrapping
(getting the value out) of primitive data types, that have "wrapper" classes. So int and Integer can
(almost always) be used interchangeably in Java language, meaning a method void giveMeInt(int
i) { ... } can take int as well as Integer as a parameter.
Typecast in Java
o In Java, you can use casts to polymorph one class into another, compatible one. For example:
o long i = 10l;
o int j = (int) i;
long k = j;
Here we see, that, while narrowing (long i -> int j) requires an explicit cast to make sure the
programmer realizes, that there may be some data or precision loss, widening (int j -> long k) does
not require an explicit cast, because there can be no data loss (long can take larger numbers than int
allows).
print("Before:");
print("b = " + b);
print("a.innerField = " + a.innerField);
exampleMethod(a, b);
print("After:");
print("b = " + b);
print("a.innerField = " + a.innerField);
}
Will output:
Before:
b = 1
a.innerField = 0
After:
Concurrency
Exceptions
Others
Note: For a full explanation of the describeContents() method see StackOverflow. In Android Studio, you
can have all of the parcelable code auto generated for you, but like with everything else, it is always a
good thing to try and understand everything that is happening.
o finally is a code block and is used to place important code, it will be executed whether exception is
handled or not.
o class FinallyExample {
o public static void main(String[] args) {
o try {
o int x=300;
o }catch(Exception e) {
o System.out.println(e.getMessage()); }
o finally {
o System.out.println("finally block is executed");
o }
o }
}
o Finalize is a method used to perform clean up processing just before object is garbage collected.
o class FinalizeExample {
o public void finalize() {
o System.out.println("finalize called");
o }
o
o public static void main(String[] args) {
o FinalizeExample f1=new FinalizeExample();
o FinalizeExample f2=new FinalizeExample();
o f1=null;
o f2=null;
o System.gc();
o }
}