0% found this document useful (0 votes)
9 views

Code Along 02 - Intents!

Uploaded by

rhenzviloria
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Code Along 02 - Intents!

Uploaded by

rhenzviloria
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Code Along 02 – Intents!

(Done to prevent any crashing issues)


Remember:
• Intents = “Intention” of performing an activity

• Allows us to traverse from one activity to


another

• Can act as a “bridge” to pass data from one


activity to another
Method 1: Starting a new activity
• In this example, we will, at the simplest create an
app that will start a new activity from a button
press

• Make
a simple
activity
with one
button
Method 1: Starting a new activity
• At this point, right click the “app” folder
(Assuming you are in “Android” view)
Method 1: Starting a new activity
• Go to New -> Activity -> Empty Views Activity
Method 1: Starting a new activity
• Here, all you’ll have to do is give the new
activity a valid name WHILE making sure
“Generate a Layout File” is checked
Method 1: Starting a new activity
• You will automatically be provided with a
blueprint of a new
activity

• …alongside with it’s


own layout file
Method 1: Starting a new activity
• Feel free to design the second activity as you
please…

• But for demonstration


purposes, place 1 button
Method 1: Starting a new activity
• Configure your activity_main’s button to have
an onClick function
Method 1: Starting a new activity
• Configure your activity_main’s button to have
an onClick function
Method 1: Starting a new activity
• Configure your activity_main’s button to have
an onClick function

OR
Method 1: Starting a new activity
Method 1: Starting a new activity
• NOTE: As it stands, the
only way to close
activity #2 is by
pressing “Back”

• (doing so takes you back to


the main activity
as it’s what’s next
in the activity stack)

• We can change this


by adding functionality
to it’s button
Method 1: Starting a new activity
• Simply use finish() to remove
an activity from the activity
stack
Method 1: Starting a new activity
Method 2 – Passing Values
• We make use of the addExtra() method.

– First parameter = a string ID for the value (You’re


free to choose this)
– Second Parameter = The value itself.
• Can consist of any of the default data types / object
types in the Java or Kotlin API
Method 2 – Passing Values
• Edit activity_main.xml
Method 2 – Passing Values
• Configure
your
activity
Method 2 – Passing Values
• activity_second.xml
Method 2 – Passing Values
Method 2 – Passing Values
• NOTE: Make sure the name matches the
parameter you give in the “get<val>Extra()”

Source Activity:

Destination Activity:
Method 2 – Passing Values

You might also like