Intent 2
Intent 2
In this Android tutorial, we will create an example to send data from one activity to another.
This example creates two activities (FormActivity and DisplayActivity) each doing the
following functions,
o FormActivity this is the main activity which is presented to the user when
launching the application for the first time. It displays a form and allows the user to
fill and submit the form. When submitted, it retrieves the values filled by the user
and stores as Bundle in Intent and starts another activity DisplayActivity.
Uses form.xml as layout file to display the form.
o DisplayActivity it retrieves the Bundle from Intent which has values filled by the
user and display it by setting the value of view elements. Uses display.xml as
layout file to display the result.
Environment Used
JDK 6 (Java SE 6)
Eclipse Indigo IDE for Java EE Developers (3.7.1)
Android SDK 4.0.3 / 4.1 Jelly Bean
Android Development Tools (ADT) Plugin for Eclipse (ADT version 20.0.0)
Setting up development environment
To run this example, you need to setup the development environment with at least one
Android platform in your SDK environment. To install Android SDK and configure ADT plugin
for Eclipse read this page .
Prerequisites
Before proceeding with this example, it is recommended that you have completed
this HelloWorld example which explains about creating Android project, its structure,
components and how to run it in Eclipse IDE.
Android Project
Create an Android project and name it as ActivityDemo.
strings.xml
Open res/values/string.xml and replace it with following content.
01
02 <?xml version="1.0" encoding="utf-8"?>
03 <resources>
<string name="hello">Form</string>
04 <string name="display">Display</string>
05 <string name="app_name">ActivityDemo</string>
06 <string name="name">Name</string>
07 <string name="age">Age</string>
08 <string name="female">Female</string>
<string name="male">Male</string>
09 <string name="gender">Gender</string>
10 <string name="submit">Submit</string>
11 </resources>
12
XML layout files
This application uses two layout files,
res/layout/form.xml Represents first screen used by FormActivity.java