Skip to main content

Application Components of ANDROID

Android App components :
App components are the essential building blocks of an Android app. Each component is an entry point through which the system or a user can enter your app. Some components depend on others.There are four different types of app components:
  1. Activities
  2. Services
  3. Broadcast receivers
  4. Content providers
Each type serves a distinct purpose and has a distinct lifecycle that defines how the component is created and destroyed. The following sections describe the four types of app components.

Activities :
An activity is the entry point for interacting with the user. It represents a single screen with a user interface. For example, an email app might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails. Although the activities work together to form a cohesive user experience in the email app, each one is independent of the others. As such, a different app can start any one of these activities if the email app allows it. For example, a camera app can start the activity in the email app that composes new mail to allow the user to share a picture. An activity facilitates the following key interactions between system and app:
1.Keeping track of what the user currently cares about (what is on screen) to ensure that the system keeps running the process that is hosting the activity.
2.Knowing that previously used processes contain things the user may return to (stopped activities), and thus more highly prioritize keeping those processes around.
3.Helping the app handle having its process killed so the user can return to activities with their previous state restored.
Providing a way for apps to implement user flows between each other, and for the system to coordinate these flows. (The most classic example here being share.)
You implement an activity as a subclass of the Activity class. For more information about the Activity class, see the Activities developer guide.

Services :
A service is a general-purpose entry point for keeping an app running in the background for all kinds of reasons. It is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface. For example, a service might play music in the background while the user is in a different app, or it might fetch data over the network without blocking user interaction with an activity. Another component, such as an activity, can start the service and let it run or bind to it in order to interact with it. There are actually two very distinct semantics services tell the system about how to manage an app: Started services tell the system to keep them running until their work is completed. This could be to sync some data in the background or play music even after the user leaves the app. Syncing data in the background or playing music also represent two different types of started services that modify how the system handles them:
Music playback is something the user is directly aware of, so the app tells the system this by saying it wants to be foreground with a notification to tell the user about it; in this case the system knows that it should try really hard to keep that service's process running, because the user will be unhappy if it goes away.
A regular background service is not something the user is directly aware as running, so the system has more freedom in managing its process. It may allow it to be killed (and then restarting the service sometime later) if it needs RAM for things that are of more immediate concern to the user.
Bound services run because some other app (or the system) has said that it wants to make use of the service. This is basically the service providing an API to another process. The system thus knows there is a dependency between these processes, so if process A is bound to a service in process B, it knows that it needs to keep process B (and its service) running for A. Further, if process A is something the user cares about, then it also knows to treat process B as something the user also cares about. Because of their flexibility (for better or worse), services have turned out to be a really useful building block for all kinds of higher-level system concepts. Live wallpapers, notification listeners, screen savers, input methods, accessibility services, and many other core system features are all built as services that applications implement and the system binds to when they should be running.
A service is implemented as a subclass of Service. For more information about the Service class, see the Services developer guide.

Broadcast receivers :
A broadcast receiver is a component that enables the system to deliver events to the app outside of a regular user flow, allowing the app to respond to system-wide broadcast announcements. Because broadcast receivers are another well-defined entry into the app, the system can deliver broadcasts even to apps that aren't currently running. So, for example, an app can schedule an alarm to post a notification to tell the user about an upcoming event... and by delivering that alarm to a BroadcastReceiver of the app, there is no need for the app to remain running until the alarm goes off. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured. Apps can also initiate broadcasts—for example, to let other apps know that some data has been downloaded to the device and is available for them to use. Although broadcast receivers don't display a user interface, they may create a status bar notification to alert the user when a broadcast event occurs. More commonly, though, a broadcast receiver is just a gateway to other components and is intended to do a very minimal amount of work. For instance, it might schedule a JobService to perform some work based on the event with JobScheduler
A broadcast receiver is implemented as a subclass of BroadcastReceiver and each broadcast is delivered as an Intent object. For more information, see the BroadcastReceiver class.

Content providers :
A content provider manages a shared set of app data that you can store in the file system, in a SQLite database, on the web, or on any other persistent storage location that your app can access. Through the content provider, other apps can query or modify the data if the content provider allows it. For example, the Android system provides a content provider that manages the user's contact information. As such, any app with the proper permissions can query the content provider, such as ContactsContract.Data, to read and write information about a particular person. It is tempting to think of a content provider as an abstraction on a database, because there is a lot of API and support built in to them for that common case. However, they have a different core purpose from a system-design perspective. To the system, a content provider is an entry point into an app for publishing named data items, identified by a URI scheme. Thus an app can decide how it wants to map the data it contains to a URI namespace, handing out those URIs to other entities which can in turn use them to access the data. There are a few particular things this allows the system to do in managing an app:
Assigning a URI doesn't require that the app remain running, so URIs can persist after their owning apps have exited. The system only needs to make sure that an owning app is still running when it has to retrieve the app's data from the corresponding URI.
These URIs also provide an important fine-grained security model. For example, an app can place the URI for an image it has on the clipboard, but leave its content provider locked up so that other apps cannot freely access it. When a second app attempts to access that URI on the clipboard,the system can allow that app to access the data via a temporary URI permission grant so that it is allowed to access the data only behind that URI, but nothing else in the second app.
Content providers are also useful for reading and writing data that is private to your app and not shared. For example, the Note Pad sample app uses a content provider to save notes.
A content provider is implemented as a subclass of ContentProvider and must implement a standard set of APIs that enable other apps to perform transactions. For more information, see the Content Providers developer guide.
A unique aspect of the Android system design is that any app can start another app’s component. For example, if you want the user to capture a photo with the device camera, there's probably another app that does that and your app can use it instead of developing an activity to capture a photo yourself. You don't need to incorporate or even link to the code from the camera app. Instead, you can simply start the activity in the camera app that captures a photo. When complete, the photo is even returned to your app so you can use it. To the user, it seems as if the camera is actually a part of your app.
When the system starts a component, it starts the process for that app if it's not already running and instantiates the classes needed for the component. For example, if your app starts the activity in the camera app that captures a photo, that activity runs in the process that belongs to the camera app, not in your app's process. Therefore, unlike apps on most other systems, Android apps don't have a single entry point (there's no main() function).
Because the system runs each app in a separate process with file permissions that restrict access to other apps, your app cannot directly activate a component from another app. However, the Android system can. To activate a component in another app, deliver a message to the system that specifies your intent to start a particular component. The system then activates the component for you.

Activating components :
Three of the four component types—activities, services, and broadcast receivers—are activated by an asynchronous message called an intent. Intents bind individual components to each other at runtime. You can think of them as the messengers that request an action from other components, whether the component belongs to your app or another.
An intent is created with an Intent object, which defines a message to activate either a specific component (explicit intent) or a specific type of component (implicit intent).
For activities and services, an intent defines the action to perform (for example, to view or send something) and may specify the URI of the data to act on, among other things that the component being started might need to know. For example, an intent might convey a request for an activity to show an image or to open a web page. In some cases, you can start an activity to receive a result, in which case the activity also returns the result in an Intent. For example, you can issue an intent to let the user pick a personal contact and have it returned to you. The return intent includes a URI pointing to the chosen contact.
For broadcast receivers, the intent simply defines the announcement being broadcast. For example, a broadcast to indicate the device battery is low includes only a known action string that indicates battery is low.
Unlike activities, services, and broadcast receivers, content providers are not activated by intents. Rather, they are activated when targeted by a request from a ContentResolver. The content resolver handles all direct transactions with the content provider so that the component that's performing transactions with the provider doesn't need to and instead calls methods on the ContentResolver object. This leaves a layer of abstraction between the content provider and the component requesting information (for security).
There are separate methods for activating each type of component:
1.You can start an activity or give it something new to do by passing an Intent to startActivity() or startActivityForResult() (when you want the activity to return a result).
2.With Android 5.0 (API level 21) and later, you can use the JobScheduler class to schedule actions. For earlier Android versions, you can start a service (or give new instructions to an ongoing service) by passing an Intent to startService(). You can bind to the service by passing an Intent to bindService().
3.You can initiate a broadcast by passing an Intent to methods such as sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast().
4.You can perform a query to a content provider by calling query() on a ContentResolver.
For more information about using intents, see the Intents and Intent Filters document. The following documents provide more information about activating specific components: Activities, Services BroadcastReceiver, and Content Providers.

The manifest file:

Before the Android system can start an app component, the system must know that the component exists by reading the app's manifest file, AndroidManifest.xml. Your app must declare all its components in this file, which must be at the root of the app project directory.
The manifest does a number of things in addition to declaring the app's components, such as the following:
1.Identifies any user permissions the app requires, such as Internet access or read-access to the user's contacts.
2.Declares the minimum API Level required by the app, based on which APIs the app uses.
3.Declares hardware and software features used or required by the app, such as a camera, bluetooth services, or a multitouch screen.
4.Declares API libraries the app needs to be linked against (other than the Android framework APIs), such as the Google Maps library.

Comments

Popular posts from this blog

BCA SEM 5 SHELL SCRIPT PROGRAM

1  Write a shell script to execute following commands 1. Sort file abc.txt and save this sorted file in xyz.txt 2. Give an example of : To execute commands together without affecting result of each other. 3. How to print “this is a three –line 1. Text message” 4. Which command display version of the UNIX? 5. How would u get online help of cat command? echo “sorting the file” sort abc.txt > xyz.txt echo “executing two commands” who ; ls echo “this is \n a three-line \n Text message” # use -e option if required echo “The version is `uname -a`” echo “Help of cat command” man cat 2  Write a shell script to execute following commands 1. How would u display the hidden files? 2. How delete directory with files? 3. How would user can do interactive copying? 4. How would user can do interactive deletion of files? 5. Explain two functionality of “mv” command with example? echo “1. How would u display the hidden files” echo “2. How delete directory with files” echo “3. How

C++

I NTRODUCTION TO OOP,CLASSES & OBJECTS 1. Use of scope Resolution of Operators. 2. Define a function outside a using scope resolution operators. 3. Write a program to calculate the area of circle, rectangle and square using function overloading. 4. Write a program to calculate the area of circle, rectangle and square using with class & object. 5. Write a program to demonstrate the use of returning a reference variable. 6. Create a class student,stores the details about name,roll no,marks of 5 subject,1.get function accept value of data members,2. display function to display,3.total function to return total of 5 subjects marks. 7. Create function power() in c++. & Create function power() in c++ and default argument. 8. Write a C++ program to swap the value of private data members from 2 different classes. 9. Write a program to illustrate the use of this pointer. 10. An election is contested by five candidates. The candidates are numbered 1 to 5 and the voting is do

USER- DEFINED FUNCTIONS

1. Write a program to calculate average temperature of five days.Create temp() function . 2. Write a program that uses recursive function fibo() thatgenerates a Fibonacci series containing N elements. 3. Write a program that uses a recursive function fact() that findsthe factorial of a given number N. 4. Program to find if the given no. is prime or not. The functionshould accept the number as argument and return if the no. isprime or not. 5. Write a function that accepts an array of integer values. Thefunction should find the number which divides all the othernumbers. 6. Write a user-defined function to perform Square of a number 7. Write a user-defined function to perform Area of a number 8. Write a user-defined function to perform Reverse the number 9. Write a program that uses a function to check whether anentered three digit number is palindrome or not. 10. Write a program to calculate the result of following with recursive calls offunction. 11. Simple interset with usin