26th
Dec
Android Interview Questions

Android Interview Questions

  • Nikita Singh
  • 26th Dec, 2020
  • 450 Followers

Android Interview Questions

1) What is Android?

Android is a mobile operating system based on a modified version of the Linux kernel and other open-source software, designed primarily for touchscreen mobile devices such as smartphones and tablets.

It is developed by Google and later the OHA (Open Handset Alliance). Java language is mainly used to write the android code even though other languages can be used. The goal of the Android project is to create a successful real-world product that improves the mobile experience for end-users.

2) Enlist major components of Android App?

Major components of Android Application are

  • Activities
  • Services
  • Content Providers
  • Broadcast Receiver
  • Intents
  • Widgets
  • Views
  • Fragments
  • Resources

3) What is a frament in Android?

A fragment is an independent Android component which can be used by an activity. A fragment encapsulates functionality so that it is easier to reuse within activities and layouts. A fragment runs in the context of an activity, but has its own life cycle and typically its own user interface. It is also possible to define fragments without an user interface, i.e., headless fragments.

4) List some storage options available in Android?

Android provides several options for you to save persistent application data. The solution you choose depends on your specific needs, such as whether the data should be private to your application or accessible to other applications (and the user) and how much space your data requires.

Below is the list of some storage options available in Android

  • Shared Preferences: Store private primitive data in key-value pairs.
  • Internal Storage: Store private data on the device memory.
  • External Storage: Store public data on the shared external storage.
  • SQLite Databases: Store structured data in a private database.
  • Network Connection: Store data on the web with your own network server.

5) What is APK format?

In Android apps development, Android application package (APK) is the package file format used to distribute and install application software and middleware onto Google's Android operating system. It is a compressed AndroidManifest.xml file with an extension .apk. It also includes the application code (.dex files), resource files, and other files that are compressed into a single .apk file.

6) What is ANR in Android?

ANR stands for Application Not Responding, which means that your app does not register events on the UI Thread anymore because a long-running operation is executed there.

7) What is Context in Android?

Context is the context of the current state of the application/object. It is an entity that represents various environment data . Context helps the current activity to interact with the outside android environment like local files, databases, class loaders associated with the environment, services including system-level services, and more.

A Context is a handle to the system. It provides services like resolving resources, obtaining access to databases and preferences, and so on. An android app has activities. It’s like a handle to the environment your application is currently running in. The activity object inherits the Context object.

8) What is DVM?

The Dalvik Virtual Machine (DVM) is an android virtual machine optimized for mobile devices. It optimizes the virtual machine for memory, battery life and performance.

9) What is a BuildType in Gradle?

BuildType in Gradle refers to build and packaging settings like signing configuration for a project. Common build types are 'debug' and 'release', but others may be defined.

The debug will use an android debug certificate for packaging the APK file. While release build type will use a user-defined release certificate for signing and packaging the APK.

10) What is Armv7?

ARMv7 is a version of CPU architecture developed by ARM. It is 32-bit proprietary microprocessor architecture designed by ARM Holdings.

11) What is an activity in Android?

An activity represents a single screen with a user interface just like a window or frame of Java. Android Activity is the subclass of ContextThemeWrapper class.

12) What is an intent in Android?

An Intent in the Android operating system is a software mechanism that allows users to coordinate the functions of different activities to achieve a task.

Android Intent is the message that is passed between components such as activities, content providers, broadcast receivers, services etc. It is generally used with startActivity() method to invoke activity, broadcast receivers, etc.

13) What is NDK?

Android NDK is a toolset that lets you implement parts of your app in native code, using languages such as C and C++. For certain types of apps, this can help you reuse code libraries written in those languages.

Syntax

class MyActivity : Activity() {
  /**
   * Native method implemented in C/C++
   */
  external fun computeFoo()
}

14) What is an "Emulator" in Android?

An Android emulator is an Android Virtual Device (AVD) that represents a specific Android device. You can use an Android emulator as a target platform to run and test your Android applications on your PC.

15) Please explain the lifecycle of an Activity?

Android Activity Lifecycle is controlled by 7 methods of android.app.Activity class. The android Activity is the subclass of ContextThemeWrapper class.

The 7 methods of Activity lifecycle is

  • onCreate: It is called when activity is first created.
  • onStart: It is called when activity is becoming visible to the user.
  • onResume: It is called when activity will start interacting with the user.
  • onPause: It is called when activity is not visible to the user.
  • onStop: It is called when activity is no longer visible to the user.
  • onRestart: It is called after your activity is stopped, prior to start.
  • onDestroy: It is called before the activity is destroyed.

16) What is snackbar in Android?

Snackbar in android is a new widget introduced with the Material Design library as a replacement of a Toast.

It is a light-weight widget and they are used to show messages in the bottom of the application with swiping enabled. Snackbar android widget may contain an optional action button.

17) What is use of FLAG_ACTIVITY_CLEAR_TASK?

If FLAG_ACTIVITY_CLEAR_TASK flag is set in an Intent passed to Context#startActivity then, this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started.

18) What is service in Android? List its types?

Android service is a component that is used to perform operations on the background such as playing music, handle network transactions, interacting content providers, etc. The service runs in the background indefinitely even if the application is destroyed.

There are four different types of Android services:

  • Bound Service
  • IntentService
  • Started Service
  • Hybrid Service

19) Explain the use of AsyncTasks?

AsyncTask is an abstract Android class that helps the Android applications to handle the Main UI thread in an efficient way. AsyncTask class allows us to perform long-lasting tasks/background operations and show the result on the UI thread without affecting the main thread.

20) What is IntentService?

IntentService is a base class for Services that handle asynchronous requests (expressed as Intents) on demand. Clients send requests through Context.startService(Intent) calls; the service is started as needed, handles each Intent, in turn, using a worker thread, and stops itself when it runs out of work.

21) What are Handlers in Android?

A Handler in Android allows you to send and process Message and Runnable objects associated with a thread's MessageQueue. Each Handler instance is associated with a single thread and that thread's message queue.

22) What is Android canvas?

Canvas is a class in Android that performs 2D drawing of different objects onto the screen. The android.graphics.Canvas class can be used to draw graphics in android. It provides methods to draw oval, rectangle, picture, text, line etc.

23) What is AAPT?

AAPT stands for Android Asset Packaging Tool. It allows you to view, create, and update ZIP-compatible archives (ZIP, JAR, and APK). It can also compile resources into binary assets. It is the base builder for Android applications.

24) How do you disable onBackPressed()?

Override the onBackPressed method and do nothing if you meant to disable the back button on the device.

@Override
public void onBackPressed() {
   if (shouldAllowBack()) {
       super.onBackPressed();
   } else {
       doNothing();
   }
}

25) What is DDMS?

The Dalvik Debug Monitor Service (DDMS) is a debugging tool used in the Android platform. The Dalvik Debug Monitor Service is downloaded as part of the Android SDK. Some of the services provided by the DDMS are port forwarding, on-device screen capture, on-device thread and heap monitoring, and radio state information.

26) List some layouts available in android?

Common Android Layouts available in android are

  • LinearLayout
  • FrameLayout
  • RelativeLayout
  • PercentFrameLayout and PercentRelativeLayout
  • GridLayout
  • CoordinatorLayout

27) What are some common reasons of ANR?

There are some common reasons for ANR:

  • The app is doing slow operations involving I/O on the main thread.
  • The app is doing a long calculation on the main thread.
  • The main thread is doing a synchronous binder call to another process, and that other process is taking a long time to return.
  • The main thread is blocked waiting for a synchronized block for a long operation that is happening on another thread.
  • The main thread is in a deadlock with another thread, either in your process or via a binder call. The main thread is not just waiting for a long operation to finish but is in a deadlock situation.

28) What Is the Google Android SDK?

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.

29) What is Orientation in Android?

Orientation is a term used to describe the positioning or overall layout of an item related to other items. For example, Portrait and Landscape are two common orientations found in Android.

30) What is a PendingIntent?

A PendingIntent is a token that you give to a foreign application (e.g. NotificationManager, AlarmManager, Home Screen AppWidgetManager, or other 3rd party applications), which allows the foreign application to use your application's permissions to execute a predefined piece of code.

31) What is use of AndroidManifest.xml file?

AndroidManifest.xml file contains information of your package, including components of the application such as activities, services, broadcast receivers, content providers, etc.

Major functions performed by AndroidManifest.xml are

  • It is responsible to protect the application to access any protected parts by providing the permissions.
  • It also declares the android API that the application is going to use.
  • It lists the instrumentation classes. The instrumentation classes provide profiling and other information. These informations are removed just before the application is published etc.

32) What is a Sticky Intent?

An intent that is used with sticky broadcast, is called as sticky intent. This intent will stick with the Android system for future broadcast receiver requests.

33) What are retained fragments?

Retained fragments are fragments that will not be destroyed on configuration changes.These Fragment will be retained even if the configuration change causes the underlying Activity to be destroyed.

34) What are Sensors in Android?

Sensors can be used to monitor the three-dimensional device movement or change in the environment of the device. Android provides sensor API to work with different types of sensors.

Different types of Sensors in Android are

  • Motion Sensors
  • Position Sensors
  • Environmental Sensors

35) Explain different launch modes in Android?

Launch mode is an instruction for Android OS which specifies how the activity should be launched. It instructs how any new activity should be associated with the current task.

There are four launch modes for activity

  • standard.
  • singleTop.
  • singleTask.
  • singleInstance.

36) What are the intent filters?

An intent filter is an expression in an app's manifest file that specifies the type of intents that the component would like to receive.

Android Intents facilitate communication between components in several ways, there are three fundamental use cases like Starting an activity, Starting a service, Delivering a broadcast.

There are two types of intents: Explicit and Implicit intents.

37) What is SQLite?

SQLite is an in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. The code for SQLite is in the public domain and is thus free for use for any purpose, commercial or private.

38) What is AppCompatActivity?

AppCompatActivity is a class that acts as the super class for activities that want to take advantage of the support library action bar features.It is qa package that is part of the Android support library which is no longer maintained.

39) What is Proguard?

ProGuard is an open-source command-line tool that shrinks, optimizes and obfuscates Java code. It is able to optimize bytecode as well as detect and remove unused instructions. ProGuard is free software and is distributed under the GNU General Public License, version 2.

40) What is taskAffinity?

taskAffinity is an attribute that is used to define the affinity of an activity. By default, all activities in an application have the same affinity. You can set this attribute to group them differently, and even place activities defined in different applications within the same task. To specify that the activity does not have an affinity for any task, set it to an empty string.

41) What is Toast in Android?

An Android Toast is a small message displayed on the screen, similar to a tooltip or other similar popup notification. A Toast is displayed on top of the main content of an activity, and only remains visible for a short time period.

42) How is data stored in Shared Preferences?

Android provides many ways of storing data of an application. One of this way is called Shared Preferences. Shared Preferences allow you to save and retrieve data in the form of key, value pair.

43) What is a StateListDrawable?

StateListDrawable is a Drawable that lets you assign a number of graphic images to a single Drawable and swap out the visible item by a string ID value. It can be defined in an XML file with the element. Each state Drawable is defined in a nested element.

44) What is drawer layout in Android?

Drawer Layout in Android is the root layout in which we define a FrameLayout and a Navigation View. In Navigation View we set the items from menu file and FrameLayout is used to replace the Fragments on the click of menu items.

45) What is Android Jetpack?

Jetpack is a suite of libraries, tools, and guidance to help developers write high-quality apps more easily. These components help you follow best practices, free you from writing boilerplate code, and simplify complex tasks, so you can focus on the code you care about.

Jetpack comprises the androidx.* package libraries, unbundled from the platform APIs. This means that it offers backward compatibility and is updated more frequently than the Android platform, making sure you always have access to the latest and greatest versions of the Jetpack components.

46) How to start/stop a service in Android?

A Service in Android is a component that runs in the background to perform long-running operations without needing to interact with the user and it works even if an application is destroyed. A service can essentially take two states i.e Started and Bound.

Whenever you want to start a service or stop a service all you need is

To Start

startService(new Intent(this, MainService.class));

To Stop

 stopService(new Intent(this, MainService.class)); 

Note before starting a service it needs to be declared in AndroidManifest.xml. Like,

<service android:enabled="true" android:name=".MainService" />

47) What are Broadcast Receiver in Android?

Broadcast receiver is an Android component that allows you to send or receive an Android system or application events. All the registered applicants are notified by the Android runtime once an event happens. It works similarly to the publish-subscribe design pattern and used for asynchronous inter-process communication.

48) What is Android Bound Service?

A bound service in Android is the server in a client-server interface. It allows components (such as activities) to bind to the service, send requests, receive responses, and perform interprocess communication (IPC).

49) What is DialogFragment?

A DialogFragment is a fragment that displays a modal window, floating on top of the current activity window. An instance of DialogFragment can be used to display an existing Dialog implementation dialog or a custom view hierarchy. The Dialog class is the base class for implementing a dialog.

50) What is presenter in Android?

Presenter in Android is the middleman or mediator between View and Model which holds responsibilities of everything which has to deal with presentation logic in your application. In general terms, the Presenter does the job of querying your Model, updating the View while responding to the user's interactions.

51) What is Bitmap pooling in android?

Bitmap pooling is a simple technique, that aims to reuse bitmaps instead of creating new ones every time. Bitmap pooling is used to avoid continuous allocation and deallocation of memory in your application, which reduces GC overhead, which results in a smooth-running application.

52) What is Android RecyclerView?

Android RecyclerView is a flexible and efficient version of ListView. It is a container for rendering a larger data set of views that can be recycled and scrolled very efficiently.

53) What is a ViewHolder Pattern?

The ViewHolder design pattern enables you to access each list item view without the need for the lookup, saving valuable processor cycles. Specifically, it avoids frequent call of findViewById() during ListView scrolling, and that will make it smooth.

54) What is rooting in Android?

Rooting is the process of allowing users of smartphones, tablets, and other devices running the Android mobile operating system to attain privileged control (known as root access) over various Android subsystems.

55) What is WebView in Android?

Android WebView is a system component for the Android operating system (OS) that allows Android apps to display content from the web directly inside an application.

56) What is a SurfaceView?

A SurfaceView is a custom view in Android that can be used to drawn inside it. SurfaceView provides a dedicated drawing surface embedded inside of a view hierarchy. You can control the format of this surface, however, the SurfaceView takes care of placing the surface at the correct location on the screen.

57) What is a Spannable in Android?

A spannable is a TextView in Android that can be used to highlight a particular portion of text with a different color, style, size, and/or click event in a single TextView widget.

58) What is use of onTrimMemory() method?

onTrimMemory(int) method is used to incrementally release memory based on current system constraints.It is called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process.

59) What is DEX File?

A dex file is a Dalvik Executable File which is an optimized class file that runs on the Dalvik virtual machine. An app is compiled into a class file and then it is optimized to a dex file because of this, the size of the dex file is always limited in size than the class file.

60) What is Espresso?

Espresso is a testing framework for Android to make it easy to write reliable user interface tests.Espresso automatically synchronizes your test actions with the user interface of your application. The framework also ensures that your activity is started before the tests run.

Leave A Comment :

Valid name is required.

Valid name is required.

Valid email id is required.

Related Interview Questions