Android basic Component

By ukmodak | March 31st 2024 10:30:09 AM | viewed 962 times
  1. Activities
  2. Intent
  3. Broadcast Receivers
  4. Services
  5. Content Providers
  6. Widgets
  7. Notifications

Activities

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.

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

  1. Started
  2. Bound
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.

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

Intents

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:

  1. Implicit Intents
  2. Explicit intents
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

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.

Broadcast Receiver

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

Intents are of two types:

  1. Normal Broadcasts
  2. Ordered 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.

Widgets

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

  1. Informational Widget
  2. Collection Widgets
  3. Collection Widgets
  4. Control Widgets
  5. Hybrid Widgets
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

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.

bONEandALL
Visitor

Total : 27273

Today :9

Today Visit Country :

  • United States
  • Sweden
  • Singapore
  • Russia