Android IQ

What is difference between Serializable and Parcelable ? Which is best approach in Android ?


Serializable is a standard Java interface. You simply mark a class Serializable by implementing the interface, and Java will automatically serialize it in certain situations.

Parcelable is an Android specific interface where you implement the serialization yourself. It was created to be far more efficient than Serializable, and to get around some problems with the default Java serialization scheme.



What is the difference between Service and IntentService? How is each used?


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. Writing an IntentService can be quite simple; just extend the IntentService class and override the onHandleIntent(Intent intent) method where you can manage all incoming requests.


What is an Intent? Can it be used to provide data to a ContentProvider? Why or why not?


The Intent object is a common mechanism for starting new activity and transferring data from one activity to another. However, you cannot start a ContentProvider using an Intent.

When you want to access data in a ContentProvider, you must instead use the ContentResolver object in your application’s Context to communicate with the provider as a client. The ContentResolver object communicates with the provider object, an instance of a class that implements ContentProvider. The provider object receives data requests from clients, performs the requested action, and returns the results.


Describe three common use cases for using an Intent?


To start an activity: You can start a new instance of an Activity by passing an Intent to startActivity() method.

To start a service: You can start a service to perform a one-time operation (such as download a file) by passing an Intent to startService().

To deliver a broadcast: You can deliver a broadcast to other apps by passing an Intent to sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast().


What is a ContentProvider and what is it typically used for?


A ContentProvider manages access to a structured set of data. It encapsulates the data and provide mechanisms for defining data security.

 ContentProvider is the standard interface that connects data in one process with code running in another process.


There are four Java classes related to the use of sensors on the Android platform. List them and explain the purpose of each.


Sensor: Provides methods to identify which capabilities are available for a specific sensor.

SensorManager: Provides methods for registering sensor event listeners and calibrating sensors.

SensorEvent: Provides raw sensor data, including information regarding accuracy.

SensorEventListener: Interface that defines callback methods that will receive sensor event notifications.