Android Interview Questions & Answer
AIDL is for purpose when you've to go application level communication for data and control sharing, a scenario depicting it can be : An app requires list of all contacts from Contacts app (content part lies here) plus it also wants to show the call's duration and you can also disconnect it from that app (control part lies here).
In Messenger queues you're more IN the application and working on threads and processes to manage the queue having messages so no Outside services interference here.
Messenger is needed if you want to bind a remote service (e.g. running in another process).
Creating and destroying threads has a high CPU usage, so when we need to perform lots of small, simple tasks concurrently, the overhead of creating our own threads can take up a significant portion of the CPU cycles and severely affect the final response time.
ThreadPool consists of a task queue and a group of worker threads, which allows it to run multiple parallel instances of a task.
Serializable is a standard Java interface. Parcelable is an Android specific interface where you implement the serialization yourself. It was created to be far more efficient than Serializable (The problem with this approach is that reflection is used and it is a slow process. This mechanism also tends to create a lot of temporary objects and cause quite a bit of garbage collection.).
Serialization Serialization is the process of converting an object into a stream of bytes in order to store an object into memory, so that it can be recreated at a later time, while still keeping the object's original state and data.
How to disallow serialization? We can declare the variable as transient.
Activities are basically containers or windows to the user interface. Services is a component that is used to perform operations on the background. It does not have an UI.
We need to register a LocalBroadcastReceiver in the activity. And send a broadcast with the data using intents from the background service. As long as the activity is in the foreground, the UI will be updated from the background. Ensure to unregister the broadcast receiver in the onStop() method of the activity to avoid memory leaks. We can also register a Handler and pass data using Handlers. I have detailed a sample implementation on this.
Intents are messages that can be used to pass information to the various components of android. For instance, launch an activity, open a webview etc.
Two types of intents-
- Implicit: Implicit intent is when you call system default intent like send email, send SMS, dial number.
- Explicit: Explicit intent is when you call an application activity from another activity of the same application.
Sticky Intents allows communication between a function and a service.
sendStickyBroadcast() performs a sendBroadcast(Intent) known as sticky, i.e. the Intent you are sending stays around after the broadcast is complete, so that others can quickly retrieve that data through the return value of registerReceiver(BroadcastReceiver, IntentFilter).
If you want someone to perform any Intent operation at future point of time on behalf of you, then we will use Pending Intent.
Description of the intent. For instance, ACTION_CALL - used to perform calls
Specifies the type of intent that the activity/service can respond to.