Understanding Components of Application
×
Home Courses Community Support
Gray Matter

First Step Towards Android: Introduction »

Understanding Activities and Intents »

Hands On With UI Designing In Android (Controls-Views,Widgets and Layouts) »

Updating... »

Understanding Components of Application

The components of android application are the essential building block these components are simply a piece of code and they have well defined life cycle. For example, Activity, Service, Receiver etc.

The components of application are loosely coupled  by the application manifest file. i.e. AndroidManifest.xml it describes the behavior of each component like how they interact.

The fundamental components or the core building blocks of an android application are discussed below-
 

Activity

An activity represents a single screen with a user interface i.e. they dictate the UI and handle the user interaction to the screens of smart phones, in-short Activity performs actions on the screen. If an applications contains more than one activity, then one of the activity should be declared/marked as the launcher activity it means it is presented when the application is launched. An activity is very much similar to the frame in AWT.

An activity is implemented as a subclass of Activity class as follows −

public class MainActivity extends Activity {
}


View

A view is the UI element that are drawn on screen for example-  button, lists forms, label, text field etc. Anything that you see on screen is a view.


Services

Services are the process that runs in the background for a long time. In other words we can say that services are responsible for handling the background operations associated with an application.

For example, playing music in the background while user is operating any other application; or fetching the data over the network without blocking user interaction with an activity.
A service is implemented as a subclass of Service class as follows −

public class MyService extends Service {

}

There are two types of services local and remote. Local service is accessed from within the application whereas remote service is accessed remotely from other applications running on the same device.


Intent

Intents displays notification messages to the users from within the Android enabled device. It can be used to alert the user of particular state that occurred. Users can be made to respond to impacts.

Intent is used to invoke components. It is mainly used to:

  • Start the service
     
  • Launch an activity
     
  • Display a web page
     
  • Display a list of contacts
     
  • Broadcast a message
     
  • Dial a phone call etc.

Example1 - You may write the following code to go to another activity.

Intent i = new Intent(MainActivity.this, ActivityTwo.class);
startActivity(i);

Example2- You may write the following code to view the webpage.

Intent intent = new Intent(Intent.Action_VIEW);
Intent.setData(Uri.parse(“https://www.geeklab.in”));
startActivity(intent);


Broadcast Receivers

Broadcast Receiver handles the communication between application and android operating system.

Broadcast Receivers tends to respond to broadcast messages from other applications or from the system. For example, applications can also initiate broadcasts to let other applications know that some data has been downloaded to the device and is available for them to use, so this is broadcast receiver who will intercept this communication and will initiate appropriate action.

A broadcast receiver is implemented as a subclass of BroadcastReceiverclass and each message is broadcaster as an Intent object.
 

public class MyReceiver  extends  BroadcastReceiver {
public void onReceive(context,intent){}

}


Content Provider

Content Providers are mainly used to share the data between the applications like from one application to another whenever requested. These kind of requests are handled by the methods of the ContentResolverclass. The data may be stored in the file system or in the database or somewhere else. It also handles data and database management issue.

A content provider is implemented as a subclass of ContentProvider class and must implement a standard set of APIs that enable other applications to perform transactions.

public class MyContentProvider extends  ContentProvider {

public void onCreate(){}

}


Fragment

Fragments are like parts of activity which represents a portion of user interface. An activity can display one or more fragments on the screen at the same time. You can also jump from one fragment to another carrying same or different information.

Android Manifest.xml

It is a configuration file of an application that contains information about activities, content providers, permissions etc. It is like the web.xml file in Java EE.
 

 

← Preview

Create and Customize Your AVD

Next →

Say Hello to Android (Creating First Android App)

NOTES

Our mission is to provide highly effective and quality education via innovative solutions. Geeksdemy look forward to bridge the gap between in-demand technology and academics in order to deliver innovative, easy, interesting and affordable learning across the Globe.

Courses

  • Python
  • Game Development with Unity 3D
  • Arduino
  • PCB & Circuit Designing
  • Robotics and Embedded C
  • 8051/8052 Embedded Systems
  • QuadCopter & UAV
  • MATLAB with Robotics
  • Raspberry Pi
Learn On the Go!
Get the Android App
Get the iOS App