Android Interview Questions PDF
Android Interview Questions PDF
It is highly customizable. Users can modify the look and feel of their
devices, install custom ROMs, and make other changes to the platform.
Multitasking
Security
2. RelativeLayout
3. ConstraintLayout
4. FrameLayout
5. TableLayout
These messages are sent by the Android system or by other applications on the
device. They indicate changes in the device's state, such as the device's battery
level, network connectivity, or incoming phone calls.
be started.
When you serialize an object using Parcelable is generally faster than Serializable
Serializable, it creates a lot of temporary because it generates less garbage and involves less
objects, which can negatively impact reflection. It is designed to be more efficient and can
performance in some cases. be faster in situations where performance is a
concern.
It is less efficient than the Parcelable interface It is more efficient than Serializable. It generally
because it carries huge data streams. produces smaller data streams.
When you implement Serializable, you don't It requires you to write custom code to handle the
have to write any special methods, but the serialization and deserialization process. This gives
serialization and deserialization process is you more control over how the object is serialized
handled entirely by the Java serialization and can allow you to optimize the process for
system. performance.
Serializable is compatible with Java, so you It is specific to Android and can only be used within
can use it to pass objects between Android and the Android framework.
non-Android systems.
13. What is the Android Manifest file, and what is its purpose?
The Android Manifest file is an XML(Extensible Markup Language) file. It provides
essential information about an Android app for the Android OS. It is named
"AndroidManifest.xml" and is located in the root directory of an Android project.
is doInBackground().
It shares resources with the parent process, It requires more resources (such as memory) than a
which can make them more efficient in terms of thread, as each process has its own set of
resource usage. resources.
Threads within a process share the same Each process is isolated from other processes,
memory space, which can make them vulnerable which provides better security and fault isolation.
to bugs and security issues.
Switching between threads is faster, as threads Switching between processes is slower than
share the same memory space and VM. switching between threads, as each process has its
own memory space and VM.
By using these lifecycle methods, an Android app can gracefully handle different
user interactions and system events and ensure that the app is efficient and
responsive at all times.
displayed.
2. Call the method show() on the Toast object to display the message.
Here is an example code snippet demonstrating how to create and display a simple
Toast message:
// create a Toast object with a short duration and a message to display
Toast.makeText(getApplicationContext(), "Hello, Ninjas. This is a toast",
Toast.LENGTH_SHORT).show();
There are some standard techniques for optimizing the performance of an Android
application:
Reducing the number of layout hierarchies: The more complex the
layout hierarchy is, the more time it takes to draw and display the user
interface. Therefore, it is essential to keep the layout hierarchy as simple
as possible.
Use the proper data structure: Choosing the right data structure is
essential for the performance of your application.
These sensors are built into most modern Android devices and can include sensors
such as:
Accelerometer: It detects the changes in the device's acceleration and
orientation.
Light sensor: It detects changes in the ambient light levels and adjusts
the device's brightness according to it.
These sensors can be accessed through the Android Sensor API. It provides
developers with a simple and consistent way to access the data from these sensors.
Developers can use this data to create various applications.
Item decorations
Item animations
26. What do you mean by an adapter in Android, and why do we need this?
An adapter in Android is a necessary component that connects a data source to a
view. It creates views for data items and manages the data and views binding. It
provides a bridge between the data source and the UI. It is responsible for creating
the views that represent the data. It also manages the data as it is displayed to the
user. An adapter extends the BaseAdapter or RecyclerView.Adapter class to provide
the necessary functionality.
Adapters in Android are commonly used to populate views such as ListView,
GridView, and RecyclerView. They are also used in other UI components such as
Spinners, AutoCompleteTextView, and SearchView.
The first step consists of the compilation of the resources folder using the Android
Asset Packaging Tool (AAPT). These are compiled into a single class file known as
R.java, which only holds constants.
In the second step, the java source code needs to be compiled to .class files using
javac, which are then converted to Dalvik bytecode using the ‘dx’ tool, which is one of
the tools in the software development kit. The final output file is classes.ex.
In the third and final step, the Android apk builder is required to take all the inputs
and build the Android Packaging Key (APK) file.
The following is a list of the most popular programming languages that can be used
to develop applications for Android:
Java: One of the most popular programming languages, Java has always been a
starting point for new developers and is used by many who work with Android
development.
Kotlin: Kotlin is a relatively new, modern, safe, and object-oriented cross-platform
programming language. When Android Studio 3.0 was released in Oct 2017, Kotlin
was announced as the official programming language for Android. Many popular
applications such as Trello, Square, and Corda have since then shifted to Kotlin.
C#: Using the C# language developers can build native iOS and Android mobile
applications.
Python: Python has emerged as one of the most popular programming languages in
recent times. A dynamic and object-oriented programming language, Python is very
popular in machine learning.
Android Software Development Kit (SDK) and Virtual Device Manager: This tool
is used to generate and handle Android Virtual Devices (AVD) and SDKs. Through
the emulator in the AVD, you can specify the supported SDK version, storage in the
SD card, screen resolution, and other abilities such as GPS and touch screen.
The Android Emulator: The AE is the implementation of the Android Virtual
Machine, designed to run processes within a virtual device itself, which can be used
on a development computer. The main use of this tool is in testing and debugging
Android applications.
Android Debug Bridge (ADB): The ADB is a command-line debugging application
doled out with the SDK. It enables developers to communicate with the device, and
facilitates actions such as the installation and debugging of an application.
Android Asset Packaging Tool (AAPT): The AAPT builds the ‘.apk’ distributable
Android package file.
gen: gen contains the compiler-generated .R file which references all the resources
in the project
src: src holds the .java source files in our project
bin: bin contains the .apk file built by the ADT during the build process, along with all
the other things needed to run an Android application
AndroidManifest.xml: This file is the manifest file that explains the basic features of
the application and defines all its components
res/values: res/values is a directory for other various XML files that contain
resources such as strings, color definitions and more
res/drawable-hdpi: This is a directory for objects that are drawable and designed for
high-density screens
res/layout: It is a directory of files that define the UI for your application
OnCreate(): The views are created and data is collected from bundles
OnStart(): Called if the activity is visible to the user. It may be succeeded by
onResume() if the activity reaches the foreground and onStop() if it converts into
hidden.
OnResume(): Called when the activity starts an interaction with the user
OnPause(): Called when the activity is going to the background but hasn’t been
killed yet
OnStop(): Called when you are no longer visible to the user
OnDestroy(): Called when the activity is finishing
OnRestart(): Called after the activity has been stopped, prior to it being started again
Low investment and better returns: Android development has a low entry barrier
and is suitable for new developers looking to become proficient in the programming
field
Free SDK: One of the most prominent features of Android is that the Software
Development Kit is open source and is provided free of charge, which eradicates the
cost of licensing distribution and development fee
Easy Adoption: Android applications are scripted in Java, which is one of the most
used programming languages in the world
Reusable: Android components can be reused and even replaced by the framework
Multi-Platform Support: The Android platform supports major OSs such as Linux,
Mac OS, and Windows
Support for Wearable Devices: The market is now flooded with wearable devices
and Android has emerged as leading support for such devices that are now readily
available in the market
Fake Applications: There are thousands of fake apps available on the market at any
given time, which when installed may try to steal your data.
Streamlining issues: There are a variety of Android devices available in the market,
with different screen sizes and dimensions, but more importantly, different Android
Operating Systems. Every application developer has to constantly work towards
updating their application for the new OS but with various OS versions and upgrades,
the process is quite difficult. An application that runs smoothly on one version of the
Android OS might crash on a different Android OS.
Background Processes: The abundance of running processes in the background is
always an issue, as they eat up the battery quickly.
Linux Kernel: The Linux Kernel forms the basis of the Android platform, and this
powers features such as memory and power management, and various drivers. It
serves as an abstraction layer before the other layers.
Platform Libraries: Android’s platform libraries are native C and C++ libraries that
provide support for graphics and media, and a WebKit library. This allows developers
to implement graphic functionality and display web content, among other things.
Android Runtime: Android Runtime (ART) and the core libraries are among the
most significant parts of the architecture. It serves as the foundation for the
application framework, and has features like optimized garbage collection.
Android applications: This is what you see when you use your phone, and is the
top level of the architecture. Core apps like email, SMS, and contacts come pre-
installed.
Application Framework: The application framework contains classes that are used
in the creation of an application. They provide the building blocks with which you can
create apps, and provide services such as a resource manager, notification manager,
and activity manager.
AlertDialog: AlertDialog supports 0-3 buttons, along with a list of selectable items,
such as radio buttons and checkboxes
DatePickerDialog: Used for the selection of date by the user
TimePickerDIalog: Used for the selection of time by the user
ProgressDialog: Used to display a progress bar and is an extension of the
AlertDialog. It also supports the addition of buttons.
Position Sensor: It is used to measure the physical position of the Android device.
This includes orientation sensors and magnetometers
Motion Sensors: These sensors include gravity, rotational activity, and acceleration
sensors which measure the rotation of the device or the acceleration and much more.
Environmental Sensor: It includes sensors that measure temperature, pressure,
humidity, and other environmental factors
18. Name some testing scenarios for real devices, not on emulators.
Emulators are devices that are used to perform tasks comparable to that of real
Android devices, and are used to decrease the cost of testing.
But some scenarios can only be performed on real devices. These scenarios
include:
Messaging
Bluetooth
Mounting and unmounting the memory card
Validation of battery scenarios
Memory related issues
Validation of the performance
separate from the current context or when you are passing a context beyond the
scope of activity.
Free Memory: As there is a limited amount of space on mobile devices, you can try
by freeing up memory space for the application to function properly
Compatibility Check: It may not be a hardware problem, but more of a software
issue. It is not always possible to test an application for all devices and Operating
Systems. There might be a chance that the application is not compatible with your
OS, so check the compatibility on the application’s Google Play Store page.
Memory Management: Some applications run perfectly on one mobile device but
may crash on other devices. This is where processing power, memory management,
and CPU speed come into play. Check the application memory requirements if the
application crashes constantly.
App Data Usage: 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
Port forwarding
Location data spoofing
Screen capture
Logcat
Radio state information
Thread and Heap information
The DDMS tool is now deprecated and Android now suggests the users use Android
Profiler instead.
Explicit Intent: An explicit intent is where you inform the system about which activity
or system component it should use to generate a response to this intent.
Implicit Intent: An implicit intent allows you to declare the action you wish to carry
out, after which the Android system will check which components are registered to
handle that specific action.
25. What is the AndroidManifest.xml file and why do you need this?
The AndroidManifest.xml file contains information about the application, which is
then provided to the Android system. This data may include the package name,
components such as activity, services, content providers, and more. This file
executes the following tasks:
Standard: This launch mode generates a new instance of the activity in the task from
which it originated. It is possible to create multiple instances of the same activity,
which can be added to the same or different tasks.
SingleTop: This launch mode is similar to the Standard launch mode, except if there
exists a previous instance of the activity on the top of the stack, then a new instance
will not be created, but the intent will be sent to the existing instance of the activity.
SingleTask: This launch mode will always create a new task and push a new
instance to the task as the root one.
SingleInstance: This launch mode is the same as the SingleTask launch mode but
the system doesn’t launch any new activities in the same task. In a scenario where
the new activity is launched, it is launched in a separate task.
String
List
Map
charSequence
INT, Long, Char, Boolean (Java data types)
30. Name the different data storage options available on the Android
platform.
Android platform provides a variety of data storage options that can be used
depending on the need of the user. The storage options are:
Activities Services
Closed Open
Not designed to run behind the scenes Designed to run behind the scenes
Loop 1, Entire Lifetime: The activity happens between onCreate and onDestroy.
Loop 2, Visible Lifetime: The activity happens between onStart and onStop
Loop 3, Foreground Lifetime: The activity happens between onResume and
onPause