Let’s see the common and some importance Android Interview Questions and Answers for 2018 and beyond. Dedicated by expert Android Developers
Top Android Interview Questions and Answers
What is a ContentProvider and what it is typically used for?
A ContentProvider manages access to a structured set of data. It encapsulates the data and offers mechanisms for defining data security. ContentProvider is the standard interface that connects data in one process with code running in another process.
Describe 3 common use cases for using Intent?
Common use cases for using Intent are:
To start an activity: You can begin a new instance of an Activity by passing Intent to startActivity() Method
To start a service: You can initiate a service to perform a one-time operation (such as download a file) by passing Intent to startService()
To deliver a broadcast: You can deliver a broadcast to other apps by passing Intent to sendBroadcast(), sendOrderedBroadcast(), or sendStrickyBroadcast()
Where MyService accesses a remote server via an internet connection.
If the Activity is showing an animation that indicates some kind of progress, what issue might you encounter and how could you address it?
Responses from a distant service via the Internet can often take some time, either due to networking latencies, or load on the remote server or the amount of time it takes for the remote service to process and respond to the request.
As a result, if such a delay occurs, the animation in the activity (and even worse, the entire UI thread) could be blocked and could appear to the user to be “frozen” while the client waits for a response from the service. This is because the service is started on the main application thread (or UI thread) in the Activity.
The problem can (and should) be avoided by relegating any such remote requests to a background thread or, when feasible, using an asynchronous response mechanism.
What is DDMS? Describe some of its capabilities?
DDMS is the Dalvik Debug Monitor Server that ships with Android. It provides a wide array of debugging features including:
- Port-forwarding services
- screen capture
- thread and heap information
- network traffic tracking
- incoming call and SMS spoofing
- simulating network state, speed, and latency
- location data spoofing
Why cannot you run standard Java byte code on Android?
Android uses Dalvik Virtual Machine (DVM) which requires a special bytecode. First of all, we have to convert Java class files into Dalvik Executable files using an Android tool called “dx”. In normal circumstances, developers will not be using this tool directly and build tools will care for the generation of DVM compatible files.
What is the difference between a regular .png and nine-patch image?
It is a resizable bitmap resource that can be used for backgrounds or other images on the device. NinePatch class permits drawing a bitmap in nine sections. The nine patch images have extension as.9.png. It allows extension in 9 ways, i.e. 4 corners that are unscaled, 4 edges that are scaled in 1 axis, and the middle one that can be scaled into both axes.
What is ADB?
ADB stands for Android Debug Bridge. It is a command line tool that is used to communicate with the emulator instance. ADB can control your device over USB from a computer, copy files back and forth, install and uninstall apps, run shell commands, and more. It is a client-server program that includes three components:
- A client, which runs on your development machine. You can invoke a client from a shell by issuing an ADB command. Other Android tools such as DDMS also create ADB clients.
- A server, which runs as a background process on your development machine. The server manages communication between the client and the ADB daemon running on an emulator or device.
- A daemon, which runs as a background process on each emulator or device instance.
What is Armv7
There are 3 CPU architectures in Android. ARMv7 is the most common as it is optimised for battery consumption. ARM64 is an evolved version of that that supports 64-bit processing for more powerful computing. ARMx86, is the least used for these three, since it is not battery friendly. It is more powerful than the other two.
How to prevent the data from reloading and resetting when the screen is rotated?
- The most basic approach would be to use a combination of ViewModels and onSaveInstanceState() So how we do we that?
- Basics of ViewModel: A ViewModel is LifeCycle-Aware. In other words, a ViewModel will not be destroyed if its owner is destroyed for a configuration change (e.g. rotation). The new instance of the owner will just re-connected to the existing ViewModel. So if you rotate an Activity three times, you have just created three different Activity instances, but you only have one ViewModel.
- So the common practice is to store data in the ViewModel class (since it persists data during configuration changes) and use OnSaveInstanceState to store small amounts of UI data.
- For instance, let’s say we have a search screen and the user has entered a query in the Edittext. This results in a list of items being displayed in the RecyclerView. Now if the screen is rotated, the ideal way to prevent resetting of data would be to store the list of search items in the ViewModel and the query text user has entered in the OnSaveInstanceState method of the activity.
Difference between Service & Intent Service
- Service is the base class for Android services that can be extended to create any service. A class that directly extends Service runs on the main thread so it will block the UI (if there is one) and should therefore either be used only for short tasks or should make use of other threads for longer tasks.
- IntentService is a subclass of Service that handles asynchronous requests (expressed as “Intents”) on demand. Clients send requests through 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.
What are Handlers?
Handlers are objects for managing threads. It receives messages and writes code on how to handle the message. They run outside of the activity’s life cycle, so they need to be cleaned up properly or else you will have thread leaks.
- Handlers allow communicating between the background thread and the main thread.
- A Handler class is preferred when we need to perform a background task repeatedly after every x seconds/minutes.
Experienced Digital Marketing professional with a demonstrated history of working in the information technology and services industry. Skilled in Search Engine Optimization (SEO), Landing Page Optimization, Adwords, Search Engine Marketing, HTML, CSS, WordPress, and Social Media Optimization (SMO). Now working with DeveloperOnRent a fast growing IT outsourcing Company