You are on page 1of 2

Android

Android Application Components or Building blocks: -


Any Application to be developed on Android Platform should be using various components such as
Activities, background services, content providers, Intents, broadcast receivers, widgets and
notifications etc., so these components can be treated as basic building blocks of Android
application.
1. Activity This is how you write an Android user interface. A single activity defines a single screen
with a user interface. When you write a user interface for your home screen it will most likely extend
the Activity class. It defines simple lifecycle methods onCreate, onResume, onPause which lets you
handle interruptions.
2. Service it does the majority of processing for your application. Its the logic behind the user
interface. For example, performing a long running process in the background. You can sub class the
Service class to write your own custom service.
3. Content Provider This provides a uniform singular interface to the content & data. The content
can be your app being exposed to the system or other apps or it could be system content e.g.
pictures on your phone, contact lists exposed or available to your app via the Content Provider
interface. It provides a consistent interface to retrieve/store data via RESTful model supporting
CRUD operations.
4. Broadcast Receiver The application modules communicate with each other using the broadcast
receiver. Messages can be initiated by the system or the app. E.g. if a user is using your app and a
phone call comes in, the Broadcast Receiver interface will notify your app and your can code to
handle that interruption (by possibly delegating to your service). You can opt to receive messages
statically via declaring in the manifest file or dynamically by programmatically registering it the code
which extends the Broadcast Receiver interface.
5. Intents Often main components we discussed so far, this is the most interesting. Intents can be
implicit or explicit. E.g. an explicit intent can be to invoke another screen when a button is pressed
on the Activity (UI) in context. An implicit intent is when you create intent and hand it off to the
system to handle it.
A good example discussed in one of google I/O boot camp was the barcode example, the app creates
an implicit intent of type SCAN and provides it to another app which handles scanning and returns
the resultCode back to the calling application.
a) Intents and Intent Filters:-
Intent: - Intent is a messaging object you can use to request an action from another app component.
Usage: - a) To start an activity, b) To start a service, c) To deliver a broadcast.

Intent Types:-
Explicit intents: - specify the component to start by name (the fully-qualified class name).
Implicit intents do not name a specific component, but instead declare a general action to
perform, which allows a component from another app to handle it.

Key Event: - Key events are nothing but we can give the some action to the key by using of key
codes. In android so many key codes are availableACTION_DOWN, ACTION_UP etc. We can get this
events through the getKeyCode(), getScanCode(), getMetaState()
Categories:-
Foreground, background, intermittent and widget-based
Android Architecture:-
Android Architecture is made up of 4 key components: - Linux Kernel - Libraries - Android
Framework - Android Applications
Android Testing:-
One can test the application on Android platform in 3 ways- 1. To use official emulator for testing
which comes with Andorid SDK. 2. To test the application on actual physical device 3. To use the 3rd
party cloud-based mobile testing platform.
AsyncTask:-
AsyncTask is an abstract class that provides several methods managing the interaction between the
UI thread and the background thread. It implementation is by creating a sub class that extends
AsyncTask and implementing the different protected methods.
By using of AsyncTask we need to call the 5 methods.
1. onPreExecute: the first method called in the AsyncTask, called on the UI thread.
2. doInBackground: the method that executes the time consuming tasks and publish the task
progress, executed in background thread.
3. onProgressUpdate: method that updates the progress of the AsyncTask, run on the UI thread.
4. onPostExecute: the final method that gets called after doInBackground finishes, here we can
update the UI with the results of the AsyncTask.
5. onCancelled: gets called if the AsyncTask.cancel() methods is called, terminating the execution of
the AsyncTask.

You might also like