android dev lecture06

20
Mobile Application Development Part 1: Android Application Development Lecture 6

Upload: -

Post on 15-Jan-2016

236 views

Category:

Documents


0 download

DESCRIPTION

ش رح

TRANSCRIPT

Page 1: Android Dev Lecture06

Mobile Application Development

Part 1: Android Application Development

Lecture 6

Page 2: Android Dev Lecture06

Outline

• Chapter 2: Activities, Fragments, and Intents• The life cycles of an activity

• Using fragments to customize your UI

• Applying styles and themes to activities

• How to display activities as dialog windows

• Understanding the concept of intents

• Using the Intent object to link activities

• How intent filters help you selectively connect to other activities

• Displaying alerts to the user using notifications

Page 3: Android Dev Lecture06

Activities, Fragments, and Intents Part 3

Page 4: Android Dev Lecture06

Linking Activities Using Intents

• When your application has more than one activity, you often need to navigate from one to another.

• In Android, you navigate between activities through what is known as an intent.

• An intent is very important but somewhat abstract concept in Android.

• The following Try It Out shows how to add another activity to an existing project and then navigate between the two activities.

Page 5: Android Dev Lecture06

Linking Activities with Intents Steps 1-3

1. Using Eclipse, create a new Android project and name it UsingIntent.

2. Right-click on the package name under the src folder and select New ➪Class

3. Name the new class SecondActivity and click Finish.

Page 6: Android Dev Lecture06

Linking Activities with Intents

Step 4

Page 7: Android Dev Lecture06

Linking Activities with Intents

Step 5• Make a copy of the main.xml

file (in the res/layout folder) by right-clicking on it and selecting Copy.

• Then, right-click on the res/layout folder and select Paste.

• Name the file secondactivity.xml.

• The res/layout folder will now contain the secondactivity.xml file

Page 8: Android Dev Lecture06

Linking Activities with Intents

Step 6

Page 9: Android Dev Lecture06

Linking Activities with Intents

Step 7

Page 10: Android Dev Lecture06

Linking Activities with Intents

Step 8

Page 11: Android Dev Lecture06

Linking Activities with Intents

Step 9

Page 12: Android Dev Lecture06

Linking Activities with Intents Step 10

• Press F11 to debug the application on the Android emulator.

• When the first activity is loaded, click the button and the second activity will now be loaded

Page 13: Android Dev Lecture06

Assignment

• Textbook pp. 54-56 (10 Steps).

• Individual report contains output snapshots.

• Due time: After one week.

Page 14: Android Dev Lecture06

Returning Results from an Intent

• The previous activity invokes another activity but does not return a result to the current activity.

• You may have an activity that prompts the user for user name and password.

• The information entered by the user in that activity needs to be passed back to the calling activity for further processing.

• If you need to pass data back from an activity, you should instead use the startActivityForResult() method.

Page 15: Android Dev Lecture06

Returning Results from an Intent

Step 1• Add the some statements to create a

button and text in the secondactivity.xml file.

Page 16: Android Dev Lecture06

Returning Results from an Intent

Step 2

Page 17: Android Dev Lecture06

Returning Results from an Intent

Step 3

Page 18: Android Dev Lecture06

Returning Results from an Intent

Step 4• Press F11 to debug the

application on the Android emulator.

• When the first activity is loaded, click the button.

• SecondActivity will now be loaded.

• Enter your name and click the OK button.

• The first activity will display the name you have entered using the Toast class.

Page 19: Android Dev Lecture06

Assignment

• Textbook pp. 59-61 (4 Steps).

• Individual report contains output snapshots.

• Due time: After one week.

Page 20: Android Dev Lecture06

Questions?