Android Interview Question

1) What are the Android application components?

Android Application components are the necessary building blocks of an Android app and every component is an entry point through which the system/user can enter in the app.

There are four different kinds of application components:

  1. Activities
  2. Services
  3. Broadcast receivers
  4. Content providers

Each type provides a distinct purpose and has a distinct lifecycle that defines how the component is created and destroyed.

2) What is an Application class in android?

An Application class is a base class or main class in your Application starts before all other classes like Activities or services are being called. We can maintain our application’s global state here and While it is NOT mandatory that we need to extend Application class, we can do so by providing our own implementation can be creating a subclass and specifying the fully-qualified name of this subclass as the “android:name” attribute in your AndroidManifest.xml’s tag.

3) What is a Context and What are different types of Contexts?

As it name says that the context of the current application or the object. Context is like a handle to the environment our application is currently running in. We basically used two types of context.one of them is Application context – whose scope is throughout the application and other one is Activity Context – whose scope depends on the Activity Lifecycle.

4) What is an Activity?

The activity provides the window in our app in which the app draws its UI and This window typically fills the screen, but may be smaller than the app screen and float on top of other windows. Basically, one activity implements one screen in the app. For example, one of an application’s activities may implement a Preferences screen and while another activity implements a Select Photo screen.

5) What is Intent Filter?

The Intent filters are a very powerful feature of the Android platform. It provides the ability to launch an activity based not only on an explicit request, but also an implicit one too and an explicit request might tell the system to “Start and Send Email activity in the Gmail app” and Where as an implicit request tells the system to “Start a Send Email screen in any activity that can do the job.” when the app User Interface (UI) demands which app is for using in the processing a task, that is intent filter at a work. So Here’s an example of how to declare Intent Filter in android AndroidManifest:


<activity android:name=".ExampleActivity" android:icon="@drawable/app_icon">
  <intent-filter>
      <action android:name="android.intent.action.SEND" />
      <category android:name="android.intent.category.DEFAULT" />
      <data android:mimeType="text/plain" />
  </intent-filter>
</activity>

6) What is Intent?

It is a type of message or information that is passed to the components and it is used to launch an activity, display a web page, send SMS, etc. There are two kinds of intents in android:
a) Implicit Intent
b) Explicit Intent

7) What is AAPT?

AAPT2 (Android Asset Packaging Tool) is a build tool that Android Studio and Android Gradle Plugin are use to compile and package your app’s resources and AAPT2 parses, indexes, and compiles these resources into a binary format that is optimized for the Android platform.

8) What are the different types of Intents?

There are two kinds of intents:

a) Explicit intents specify in which application will satisfy the intent, by supplying either the target app’s package name or a fully-qualified component class name and here we’ll typically use an explicit intent to start a component in your own application, because we know the class name of the activity or service we want to start so For example, we might to start a new activity in android within our app in response to a user action, or start a service to download a file in the background.
b) Implicit intents does not use a specific component, but instead declares a general action to perform in which it allows a component from another app to handle it. For example, if we want to show the particular user a location on a map then we need to use an implicit intent to request that another capable app show a specified location on a map.

9) What is HandlerThread?

HandlerThread is a Handy class which is used to start a thread that has a Looper.

10) What is a Service?

A service is a component which doesn’t have UI (User Interface) and it can perform long running operations like downloading stuff, playing music etc.. in which can run even exiting the application. So By default service runs on the main thread and this might cause ANR errors. To avoid this, we use Start service by creating a new thread or use Intent Service that can do work in the background.

11) What items are important in every Android project?

These are some essential items which are present each time when Android project is created:

  • AndroidManifest.xml
  • build.xml
  • bin/
  • src/
  • res/
  • assets/

12) What is the importance of XML-based layouts?

The use of XML based layouts provides a consistent and its standard means of setting GUI definition format also In common practice the layout details are placed in XML files while other items/components are placed in source files.

13) What are containers?

Containers are as the name itself implies and holds objects and widgets together, it depends on which specific items are needed and in what particular arrangement that is wanted and the containers may hold fields, buttons, labels or even child containers, as examples.

14) What is Orientation?

Orientation can be set using setOrientation() and it dictates if the LinearLayout is represented as a row or as a column and its values are set as either HORIZONTAL or VERTICAL.

15) What is the importance of Android in the mobile market?

Developers can build and register apps that can be specifically run under the Android environment. Which means that every mobile device that is Android enabled will be able to support and run these apps and With the growing popularity of Android mobile devices, the developers can take advantage of this trend by creating and uploading their applications on the Android Market for distribution to anyone who wants to download it.

16)What do you think, are there any disadvantages of Android?

Given that Android can be 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 and One app that runs on this particular version of Android OS may or may not run on another version where Another disadvantage is that since mobile devices such as phones and tabs come in different sizes and forms so it poses a challenge for developers to create apps that can adjust correctly to the right screen size, other varying features and specs.

17) What is adb?

Adb is short for Android Debug Bridge which allows developers the power to execute remote shell commands and its basic function is to allow and control communication towards and from the emulator port.

18) What are the four essential states of an activity?

  • Active – if the android activity is at the foreground
  • Paused – if the android activity is at the background and still visible
  • Stopped – if the android activity is not visible and therefore is hidden or obscured by another activity
  • Destroyed – when the android activity process is killed or completed terminate

19) What is ANR?

ANR is short for Application Not Responding and this is actually a dialog that appears to the user whenever an application has been unresponsive for a long period of time.

20) Which elements can occur only once and must be present?

Among the different elements, it must be present and can occur only once so the rest are optional and it can occur as many times as needed.

21) How is escape characters used as an attribute?

Escape characters are preceded by double backslashes. For example, a newline character can be created using ‘\\n’

22) What is the importance of settings permissions in app development?

Permissions allow certain restrictions to be imposed primarily to protect data in the android platform. Without these, it could be compromised, resulting in defects in functionality.

23) What is the function of intent filter?

Because each and every android component needs to indicate which intents they can respond to, the intent filters which can be used to filter out intents that these components are willing to receive also one or more intent filters are possible, depending on the services and activities that are going to make use of it.

24) Enumerate the three key loops when monitoring an activity

  • Entire lifetime – android activity happens between onCreate and onDestroy
  • Visible lifetime – android activity happens between onStart and onStop
  • Foreground lifetime – android activity happens between onResume and onPause

25) When is the onStop() method invoked?

A call to onStop function happens when an android activity is no longer visible to the user, either because another android activity has taken over or if in front of that activity.

26) Is there a case where in other qualifiers in multiple resources take precedence over the locale one?

Yes, there are actually instances in which some qualifiers can take precedence over locale and there are two known exceptions, which can be the MCC (mobile country code) and MNC (mobile network code) qualifiers.

27) What are the different types of states where in a process is based?

There are 4 possible states:

  • foreground activity
  • visible activity
  • background activity
  • empty process

28) How can the ANR be prevented?

One technique that can prevent the Android system from concluding a code that has been responsive for a long period of time and it is to create a child thread. So Within the child thread the most of the actual workings of the codes can be placed, hence that the main thread runs with minimal periods of unresponsive times.

29) What role does Dalvik play in Android development?

Dalvik serves as a virtual machine in android platform, and it is where every Android application runs. Through Dalvik, the android device can be able to execute multiple virtual machines efficiently through better memory management.

30) What is the AndroidManifest.xml?

This file is essential in every application and it is declared in the root directory and contains information about the android application that the Android system must know before the codes can be executed.

31) What is the correct way of setting up an Android-powered device for an app development?

The followings are the steps to be followed prior to actual app development in an Android-powered device:
-Declare our app as “debuggable” in your Android Manifest.
-Turn on the “USB Debugging” in setting on your device.
-Set up our system to detect your device.

32) Enumerate the steps in creating a bounded service through AIDL.

  1. create the .aidl file in which it defines the programming interface
  2. Implement the interface in which it involves extending the inner abstract Stub class as well as implanting its methods.
  3. Expose the interface in which it involves implementing the service to the clients.

33) What is the importance of Default Resources?

When default resources in which it contains the default strings and files are not present, an error will occur and the app will not run and the resources are placed in specially named subdirectories under the project res/ directory/ folder.

34) When dealing with multiple resources, which takes precedence among them?

Assuming that all of these resources are able to match the configuration of the device and the ‘locale’ qualifier almost always takes the highest precedence over the others.

35) When does ANR occur?

The ANR dialog is displayed to the user based on two possible conditions and the one is when there is no response to an input event within 5(five) seconds and the other is when a broadcast receiver is not done executing within 10(ten) seconds.

36) What is AIDL?

AIDL, or Android Interface Definition Language which handles the interface requirements between a client and a service so both can communicate at the same level through interprocess communication or IPC and this process involves breaking down objects into primitives that Android can understand and this part is required simply because a process will not access the memory of the other process.

37) What data types are supported by AIDL?

AIDL has support for these following data types:
-string
-charSequence
-List
-Map
-all native Java data types i.e. long, int ,char and Boolean

38) What is a Fragment?

A fragment is a part or portion of an activity in android which is modular in a sense that we can move around or combine with other fragments in a single activity and the fragments are also reusable.

39) What is a visible activity?

The visible activity is one that sits behind a foreground dialog and it is actually visible to the user, but it will not necessarily be in the foreground itself.

40) When is the best time to kill a foreground activity?

The foreground activity and it 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 and 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.

41) Is it possible to use or add a fragment without using a user interface?

Yes, it is possible that, such as when we want to create a background behavior for a particular activity. We 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 then press and hold that icon. We 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?

There are 5 key components under the Android app architecture:
– services
– intent
– resource externalization
– notifications
– content providers

44) What composes a typical Android application project?

A project under Android app development and it upon compilation, becomes an .apk file. This apk file format is actually made up of the AndroidManifest.xml file, app code, resource files, and other related files.

45) What is a Sticky Intent?

A Sticky Intent is a broadcast from sendStickyBroadcast() function such that the intent floats around even after the broadcast and it allows others to collect data from it.

46) Do all mobile phones support the latest Android operating system?

Some Android-powered phones allow us to upgrade to the higher Android operating system version and 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 in the latest Android version.

47) What portable wi-fi hotspot?

Portable Wi-Fi Hotspot allows you to share your mobile internet connection to other wireless android devices. 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 which you have created.

48) What is an action?

In Android development, an action is what the intent sender wants to do or expected to get as a response and the 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 and the Nine-patch refers to the way you can resize the image: 4 corners that are unscaled and 4 edges that are scaled in 1 axis, and the middle one that can be scaled into both axes.

50) What language is supported by Android for application development?

The main language supported is Java programming language and java is the most popular language for app development in which it makes it ideal even for new Android developers to quickly learn to create and deploy apps in the Android environment.

Subscribe Now