The Content helps those who wish to program mobile applications using android platform. The content has been used to conduct mobile application boot camps using android platform on different regions in Tanzania
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
Android Bootcamp Tanzania:intents
1.
2.
An intent is an abstract description of an operation to be
performed.
It can be used with startActivity to launch an Activity.
An Intent provides a facility for performing late runtime
binding between the code in different applications.
Its most significant use is in the launching of activities,
where it can be thought of as the glue between
activities.
It is basically a passive data structure holding an abstract
description of an action to be performed.
3.
The primary pieces of information in an intent are:
◦ action -- The general action to be performed, such
as ACTION_VIEW, ACTION_EDIT, ACTION_MAIN, etc.
◦ data -- The data to operate on, such as a person record in
the contacts database, expressed as a Uri.
4.
There are two primary forms of intents you will use.
Explicit Intents have specified a component
(via setComponent(ComponentName) or setClass(Con
text, Class)).
Which provides the exact class to be run.
Often these will not include any other information,
simply being a way for an application to launch various
internal activities it has as the user interacts with the
application.
5.
Implicit Intents have not specified a component;
Instead, they must include enough information for
the system to determine which of the available
components is best to run for that intent.
6.
Predefined actions (http://developer.android.com/reference/android/content/Intent.html)
Action Name
Description
ACTION_CALL
Initiate a phone call
ACTION_EDIT
Display data to edit
ACTION_MAIN
ACTION_VIEW
Start as a main entry point, does not expect to
receive data.
Pick an item from the data, returning what was
selected.
Display the data to the user
ACTION_SEARCH
Perform a search
ACTION_PICK
Defined by the programmer
6
7. Intent i = new
Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://www.google.com"));
startActivity(i);
Action to perform
Data to perform the action on
Implicit intents are very useful to re-use code and to launch external
applications …
M re tha n a Co m p o ne nt c a n m a tc h the I nt re q ue s t …
o
nte
How to define the target component?
7
8.
9.
10.
In order to access external components in
android, permissions needs to be set in Android
Manifest file.
12. Explicit Intent: Specify the activity that will
handle the intent.
The following shows how to move from First
activity to second activity.
Intent a =new Intent(FirstActivity.this, SecondActivity.class);
startActivity(a);
OR
Intent about=new Intent(getApplicationContext(),About.class);
startActivity(about);
12
13.
Developers mostly create applications using
different activities.
These activities needs to communicate and pass
data from one part to the other.
For this case, Explicit Intents should be used.
14.
For activities to be able to communicate to one
another.
They must be registered in the manifest file.
This is done by adding all your activities in the
manifest file.
This is done inside the <application> tag of the
manifest
17. Creating an Options Menu
The options menu is where you should include
actions and other options that are relevant to the
current activity context.
◦ Such as "Search“,”Save” "Compose email," and
"Settings.“
◦ Ref:
http://www.droidnova.com/how-to-create-an-option-menu,427.html
18.
19.
First we have to make a new folder in our
res/layout directory .
In this new directory we will create a new xml file
named menu.xml.
Put the following code.
20.
21.
The content of the xml file should be very self
explaining.
We have an id for each item, so we have a
reference for it.
The title attribute, if defined, is nothing more than
the text you see in the option menu.
22.
The same with the icon attribute which references
to an icon, in our case the default icon.
Now we have to modify our Activity class.
First we have to override the method
onCreateOptionsMenu()
24.
Right now we can start our application and we will
see our 3 option items in our menu when we press
the menu button.
As long as nothing happens when we press one
item, the menu is senseless.
To implement a reaction of our menu, we should
override another method named
onOptionsItemSelected().