The manifest file
Before Android can start an application component, it must learn that the component exists. Therefore, applications declare their components in a manifest file that's bundled into the Android package, the.apk
file that also holds the application's code, files, and resources. The manifest is a structured XML file and is always named AndroidManifest.xml for all applications. It does a number of things in addition to declaring the application's components, such as naming any libraries the application needs to be linked against (besides the default Android library) and identifying any permissions the application expects to be granted.
But the principal task of the manifest is to inform Android about the application's components. For example, an activity might be declared as follows:
The name
attribute of the <activity>
element names the Activity
subclass that implements the activity. The icon
and label
attributes point to resource files containing an icon and label that can be displayed to users to represent the activity. Intent filters
An Intent object can explicitly name a target component. If it does, Android finds that component (based on the declarations in the manifest file) and activates it. But if a target is not explicitly named, Android must locate the best component to respond to the intent. It does so by comparing the Intent object to the intent filters of potential targets. A component's intent filters inform Android of the kinds of intents the component is able to handle. Like other essential information about the component, they're declared in the manifest file.Intent filter tag contains many information like action , category etc. In android apps the first activity have the inten filter with action value MAIN and category value LAUNCHER as shown below:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Intents
Intent is an asynchronous message which activates the three type of components - activities , services , and broadcast receivers.For activities and services, it names the action being requested and specifies the URI of the data to act on, among other things. For example, it might convey a request for an activity to present an image to the user or let the user edit some text.For broadcast receivers, the Intent object names the action being announced. For example, it might announce to interested parties that the camera button has been pressed.
There are separate methods for activating each type of component:
* An activity is launched (or given something new to do) by passing an Intent object to Context.startActivity() or Activity.startActivityForResult().
* A service is started (or new instructions are given to an ongoing service) by passing an Intent object to Context.startService().
* An application can initiate a broadcast by passing an Intent object to methods like Context.sendBroadcast(), Context.sendOrderedBroadcast(), and Context.sendStickyBroadcast() in any of their variations.Android delivers the intent to all interested broadcast receivers by calling their onReceive() methods.
Now an example of calling an activity from another activity:-
Let's make two activities splashActivity and menuActivity .
In above code calling menuActivity from splashActivity using intent object by directly specifying activity name.
when we don't know the name of the components we can use action , catagory, or data type options to call the component.
for more info on intents, intent filter and manifest file you can go to this site
http://developer.android.com/guide/topics/fundamentals.html
Bindu Kushwaha
No comments:
Post a Comment