1.4 Basic Parts of Android Application

The basic components of any android application are the following:

  • Activities
  • Intent and broadcast receivers
  • Services
  • Content Providers
  • Widgets and Notifications


Basic components of android application

Figure Main parts of  android application

Let us go through a brief introduction of these components. We shall deal with them in details in next chapters.

1.4.1 Activity

An activity is the first stepping stone is building an Android user application. It provides the space to the user for doing anything and everything. For example, opening a contact, dialing a caller, etc. everything is done by interacting with a window and that very window is provided by an activity. A window is provided to each activity where user interfacing is done. Generally, every Android application has more than one activity. There is one “main” activity. All other activities are child activities. There is a stack called back stack. Whenever, there is a new window is started, previous activity is pushed to the back stack and it is stopped until the new activity is done. As soon as the back key of your device is pressed, new activity is popped out of stack and destroyed. Now previous activity resumes.

For example, when you send SMS, you open the messenger and send message. Assume this to be your current activity. When you press back key, it should resume the previous activity right!! Previous activity was your own home screen. Let us understand it diagrammatically.

Android Activity and back stack

                                                                Figure Android Activity and back stack

If you are a novice or don’t have computer’s background, you might be thinking what the heck is this stack, push and pop kind of things. A stack is data structure in which computer organizes its data in the memory. Adding an item to this is called push operation. Deleting an item is called pop. A stack has a structure like a book shelf where you arrange your books but unlike a book shelf, only one item can be inserted and deleted from stack respectively.

1.4.2. Service

Another important component of an android application is service. It does not provide user interface. It does long running operations in background. Service doesn’t terminate even if the component which initiated it got terminated or switched to another application. A service can be connected to a component which can even do inter process communication (IPC). For example, when you receive your email updates in inbox it is a service. You get the notification of new e-mail even if you are not using the e-mail app or doing something else. Amazing isn’t it. A service can take two forms:

· Started: After a service starts, it can run indefinitely and usually performs single operation. No result is returned to user. For example, uploading a file. After the task is completed, it should terminate itself.

· Bound: In this case, a component is bound to a service so that a particular task can be completed. This type of service provides a client-server like interface. Requests can be send, receive requests, and return result to the user. Inter process communication is achieved through this service. App component can bind to a service. Multiple components can be bound to this type of service. After the destruction of component, service terminates.

     Figure Android Service can take two forms


1.4.3. Content Providers

These Android components bring the object oriented functionality to the system. Content Providers encapsulate data. Content providers as the name indicates provides content of one process to another hence it acts as an interface. It provides gateway to access data from a structured set. For accessing data in a content provider an object has to be created and this object acts as a client whereas content provider act as a server. It is this object which is going to receive the requests retrieves the results and returns the result. Android has content providers which manages video, audio, etc. These content providers are internal to android applications. For example, custom searches on device require content providers.


1.4.4. Android Intents and Broadcast Receivers

Android Intents are the communication medium .i.e., app components send messages to one another like you do with your friends. It is a messaging object. It can be used to query an action from another app component. Android Intent can be used to instantiate a new activity or get result from another activity. A service can be started by passing intent to perform a single operation. A broadcast can be sent to other apps by passing intents. Intents are of two types:

· Implicit Intents: These are used to declare general actions to be performed so that part of another app can handle it.

· Explicit intents: These are generally used to start a new element of your own application. These elements are started by their name i.e. fully qualified class name. For example, if you want to call your best friend you would do it by name and if he/she is not with you then you would definitely know the residential address. Now this is residential address is what we refer to be as fully qualified name.

     Type of Android intents


We know little bit about activity, service but what this broadcast chap is all about??? Let’s find out this in next few lines. Android Broadcast is a message which spreads out when any event occurs. They are received by apps. Android Intents can be used to deliver broadcasts to other apps. For example, when your device boots up or switched on system generates a broadcast to all apps. There should be a procedure or should be something which can receive these broadcasts. These receptors are called broadcast receivers. For this you need to register a receiver in the activity which we shall deal while programming for the same. There are two types of broadcasts:

· Normal Broadcasts: These are asynchronous in nature. Many receivers can be activated at the same time which doesn’t have any defined order. But they are very efficient.

· Ordered Broadcasts: They are synchronous in nature. Broadcast received by one receiver passes it to other receivers. Broadcasts are delivered to receiver on one-to-one and sequential basis. Either receiver will pass result to another receiver or it may completely destroy the broadcast.

      Android Broadcast are of two types


1.4.5. Android Widgets and Notifications

Android App widgets are the small application views. These views can be embedded into other applications. They can receive updates on periodic basis. Now what is a widget first of all? A widget is a quick view of your app’s functionality and data. This view is accessible from home screen of your device. Now widgets are of following types:

Figure Types of widgets


Let us find out what these four types o widgets have to say

· Informational Widget: These Android widgets are going to display only that information to user which is important and dynamic in nature. Example the information displayed on your home screen saying time and weather condition is a widget of this type.

· Collection Widgets: These Android widgets scroll in top-to-down direction. Collection of information of same type and then enabling user to open any one of them to full detail. Example is your e-mail app which will display all the mails in your inbox and then allow you to open any one o them.

· Control Widgets: Displays the most frequently used functionalities which user might want to control from home screen. For example in a video app, you can pause, play, stop, go to previous track, move to next track is an example of control widget.

· Hybrid Widgets: These Android widgets combine features of all of the above three.

Notification, as the name says keeps the user aware of events going on. User is kept informed like any news channel. For e.g, everyone of us know about facebook or whatsapp, now notification system of app is responsible for informing you about any new friend request, chat request, or a new message from say, dvs or xyz, etc.