Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
14 views39 pages

Android Intents & Activities Guide

The document discusses multiple activities and intents in Android applications. It describes creating an app with two activities and layouts, getting the first activity to call the second activity, and passing data between activities. An intent is used to start the second activity. The purpose of activities, intents, and other Android concepts are also explained.

Uploaded by

eren akarsu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views39 pages

Android Intents & Activities Guide

The document discusses multiple activities and intents in Android applications. It describes creating an app with two activities and layouts, getting the first activity to call the second activity, and passing data between activities. An intent is used to start the second activity. The purpose of activities, intents, and other Android concepts are also explained.

Uploaded by

eren akarsu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

SWE 218

Mobile
Programming
LESSON 9
Multiple activities and
Intents
Apps can contain more than one activity

An activity is a single focused


thing your user can do. If you
chain multiple activities
together to do something
more complex, it’s called a
task.
Here’s what we’re going to do in this app

1. Create an app with a single activity and layout.


2. Add a second activity and layout.
3. Get the first activity to call the second activity.
4. Get the first activity to pass data to the second
activity.
Here’s the app structure
Here’s the app structure
Update the layout
Update the layout
Update strings.xml...
...and add the method to the activity
Create the second activity and layout
What just happened?
Welcome to the Android manifest file
Every activity needs to be declared
An intent is a type of message
An intent is a type of message
Use an intent to start the second activity
What happens when you run the app
What happens when you run the app
What happens when you run the app
What happens when you run the app
Test drive the app
Pass text to a second activity
Questions
Question 1

What is the purpose of the onCreate() method in an


Android Activity class? Write an example onCreate()
method in Java.
Answer 1
Question 2

What is the purpose of the findViewById method in


Android development? Provide an example of its usage.
Answer 2

The findViewById method is used to retrieve the


view with the specified ID from the layout. It allows us
to access and manipulate UI elements
programmatically.
Question 3

Explain the difference between match_parent and


wrap_content layout attributes in Android XML
layouts.
Answer 3

match_parent tells the view to expand as much as possible within its


parent layout, filling the available space.

wrap_content tells the view to expand only enough to accommodate


its content, wrapping it tightly without any extra padding.
Question 4
Describe the purpose of the Intent class in Android and provide an
example of its usage.
Answer 4

The Intent class in Android is used for communication between


components (such as activities, services, and broadcast receivers)
within an application or between different applications.

It can be used to start activities, start services, deliver broadcasts, and


transfer data between components.
Question 5
What is the function of the onResume method in
the Android Activity lifecycle?
Answer 5

● The onResume method is called when the activity is about to start


interacting with the user.
● It is used to perform tasks that should occur every time the activity is
resumed, such as refreshing data from a database, restarting
animations, or acquiring exclusive resources.
● For example, it could be used to refresh a list of items displayed in an
activity whenever the activity comes back to the foreground after being
paused.
Question 6
Question 6
Answer 6
Resources
● https://www.siirt.edu.tr/dosya/personel/android_kitabi-siirt-2020228161632918.pdf
Thanks for listening…

You might also like