Android Interview Questions And Answers
Q: List out the Java classes that are related to the use of sensors on the android platform.
A: There are four Java classes that are related to the use of sensors on the Android platform are as follows:
- Sensor: It provides methods to identify the capabilities that are available for a specified sensor and can create an instance of specific sensor
- Sensor Manager: It provides methods for registering sensor event listeners and calibrating sensors
- Sensor event: It is used to create a sensor event object and provides the raw sensor data, accuracy of data, type of sensor that generate the event, and timestamp for an event
- Sensor event listeners: This interface is to create two callback methods that receive notification when the sensor value changes or when sensor accuracy changes
Q: What is the intent?
A: An intent is a messaging object which you can use to request an action from another app component. It is used for starting an activity, Services, or delivering a broadcast. There are two types of intents in android. They are:
- Implicit intent
- Explicit intent
Q: What is the Contentprovider?
A: A ContentProvider manages access to a structured set of data. A provider is a part of an Android application, which often provides its own UI for working with the data. Content providers are primarily intended to be used by other applications that can access the provider by using a provider client object.
Q: What is DDMS? Mention some of its capabilities?
A: DDMS is the Dalvik Debug Monitor Server. It is the bug monitoring server that comes along with android. It provides a wide range of debugging features such as
- Screen capture
- Port forwarding services
- Network traffic tracking
- Incoming call and SMS spoofing
- Location data spoofing
- Simulating network state, speed, and latency
- Thread and heap information
Q: Which method is called only once in a fragment lifecycle?
A: onAttached() is the method that can call only once in a fragment lifecycle.
Q: What is a broadcast receiver?
A: The broadcast receiver is a dormant component of the Android system. It is responsible to send the notification to the user whenever a specific event occurs like “Check your internet connection”, “Your battery is low”, etc.
Q: Explain Android application architecture?
A: The following are the components of Android application architecture:
- Services: It is used to perform background functionalities
- Intent: It is used to perform interconnection between activities and data passing mechanism
- Content providers: It is used to share the data between applications
- Notifications: Through light, sound, dialog box, icon, notification and toast
- Resource externalization: strings and graphics
Q: Mention the various storages that are provided by Android?
A: The various storages that are provided by Android are as follows:
- Internal storage
- External storage
- Shared preferences
- Network connection
- SQLite database
Q: What is the APK format?
A: Android Packaging key (APK). It is a compressed key with classes, supportive assets, UI’s, and manifest. All the files can be compressed into a single file called the APK.
Q: What are the types of flags that are used to run the application?
A: There are two types of flags that are used to run the application. They are as follows:
Q: Name the dialog box that is supported by Android?
A: The following are the dialog box that is supported by the Android:
- Progress dialog box
- Alert dialog box
- Date picker dialog box
- Time picker dialog box
Q: What are the basic tools that are used to develop an Android application?
A: The basic tools that are used to develop an Android application are as follows:
- Eclipse+ADT plugin
Q: Mention some exceptions in Android?
A: Some exceptions in Android are as follows:
- Inflate Exception
- Surface.OutofResource Exception
- SurfaceHolder.BadSurfaceType Exception
- WindowManager. BadTokenException
Q: Give a list of impotent folders in Android?
A: The list of impotent folders are as follows:
Q: What are the core building blocks of android?
A: The core building blocks of an android are as follows:
- Content provider
Q: What are the advantages of android?
A: The main advantages of android are as follows:
- It is an open-source application that can create, distribute, and develop the application for free.
- It supports Windows, Mac, and Linux platforms
- It supports various technologies like camera, Bluetooth, wi-fi, EDGE, etc.
- It uses a highly optimized virtual machine for mobile devices, called DVM (Dalvik Virtual Machine)
Q: Why byte code cannot be run in android?
A: Because android uses DVM (Dalvik Virtual Machine) rather than JVM (Java Virtual Machine).
Q: Explain the difference between onCreate and onStart?
A: onCreate() method is called when the application starts, once during the Activity lifecycle, or when the Activity has been destroyed and recreated, for example during the configuration change.
onStart() method is called whenever the Activity becomes visible to the user, typically after onCreate() or onRestart() method.
Q: Explain services?
A: A service is an application component that can run in the background, even when the user is not interacting with the application. There are three different types of services. They are as follows:
- Foreground service: It performs the operation that is noticeable to the user. For example, we use a foreground service to play an audio track. Notification must be displayed to the user.
- Background service: It performs an operation that does not notice directly by the user. In Android API level 26 and above, there are few cases that restrict the use of background service and it is recommended to use WorkManager in such cases.
- Bound service: A service is bound when an application binds to it by calling bindService(). It offers a client-server interface that allows components to interact with the service, send requests, and receive results.
Q: Mention the difference between the Service and Intent service?
A: Service is an application component that can run in the background, even when the user is not interacting with the application. A service can handle the network transactions, or can interact with a content provider, all from the background.
Intent service is a subclass of service that handles asynchronous requests on demand. Clients send the requests through intent calls. The service is started as needed, handles each intent inturn using a worker thread and stops by itself when it runs out of work.
Q: Difference between thread and Async Tasks?
A: Threads is used to separate long running operations from main thread so that to improve the performance. But it can’t be cancelled and it can’t handle configuration changes of an android.
Async Tasks are used to handle work items shorter than 5mins duration and you can update UI unlike Java. but many long running tasks will drown the performance.
Q: Difference between Activity and Service?
A: Activity is basically a container or Windows to the User interface, whereas Service is a component that is used to perform operations on the background.
Q: Difference between Serializable and parcelable?
A: Serializable is a process of converting an object into streams of bytes in order to store the object in memory, so that it can be recreated but still keeps the object’s original state and data. It is a Standard Java interface.
Parcelable is an android specific interface where you can implement a serialization interface by yourself. This mechanism tends to form a lot of temporary objects and can result in garbage folders.
Q: Explain fragments?
A: The fragment is a UI entity connected to FragmentActivity. Yourself can connect the various fragments in a single action to create a multi-pane UI and can reuse the fragment in various activities.
Q: Difference between fragment and the activity?
A: An activity is an application component that provides a screen with which the user can interact in order to do something, whereas fragment represents the portion of UI in an activity with its own lifecycle and the input events.
Q: Explain ANR and how can you prevent them from the app?
A: An ANR dialog box occurs when the UI is not responding for more than 5seconds, it usually occurs when you have blocked the main thread.
To avoid occurring the ANR errors, you should move work off the main thread as much as possible.
Q: What are the permission protection levels in android?
- Normal: A lower risk permission that provides requesting application access to isolated application level features, with minimal risk to other applications, users, or the system. The system automatically grants this kind of permission to a requesting application at installation, without asking the user approval.
- Dangerous: It is used when the app wants the data and resources that contains user private information. So the dialog of this license is to be allowed by the user except the app cannot present functionality that depends on the license.
- Signature: The system allows these app licenses at the moment of installation, but only when the app that strives to use license that is confirmed by the same certificate as the app that represents the signature permission.
Q: Explain Loader API in android?
A: The Loader API allows you to load the data from the Content provider or other data source for display in an FragmentActivity or Fragment.
- It simplifies thread management by providing call back methods when an event occurs.
- It persists and cache results across configuration changes to avoid duplicate queries.
- It runs on separate threads to prevent unresponsive UI.