8.intents - LinkActivities FPT
8.intents - LinkActivities FPT
Intent Action
Android
System
What can intents do?
● Start an Activity
○ A button click starts a new Activity for text entry
○ Clicking Share opens an app that allows you to post a photo
● Start a Service
○ Initiate downloading a file in the background
● Deliver Broadcast
○ The system informs everybody that the phone is now charging
INTENT
• Explicit Intent: Starts a specific Activity
• Implicit Intent: Asks system to find an Activity that can handle this
request
INTENT
• Explicit Intent
Intent i = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(i);
• Implicit Intent
Intent read1=new Intent();
read1.setAction(android.content.Intent.ACTION_VIEW);
read1.setData(ContactsContract.Contacts.CONTENT_URI);
startActivity(read1);
Implicit Intents - Examples
• Show a web page
Uri uri = Uri.parse("http://www.google.com");
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);
• Dial a phone number
Uri uri = Uri.parse("tel:8005551234");
Intent it = new Intent(Intent.ACTION_DIAL, uri);
startActivity(it);
7
Activity Implement
● Start another Activity
9
Communicating Between Activities
- Pass data from Activity A to Activity B.
15
Activity Stack
vity
After viewing i
t r
Ac rde
r
shopping cart, rd
O ace
e o
user decides to rt Pl
ca
vity ing rt
add more items, cti p i v ity g ca
rtA hop rtA
c t
ppi
n
then places Ca w s OrderActivity Ca w sho
Vie Place order Vie
order.
CartActivity CartActivity A
y
ctivit ms
L i s t
View shopping cart View shopping cart Food e food ite
s
Choo
FoodListActivity FoodListActivity FoodListActivity
Choose food items Choose food items Choose food items
MainActivity MainActivity MainActivity MainActivity
What do you want to What do you want to What do you want to What do you want to
do? do? do? do?
16
Classwork
● Create LoginActivity:
○ Enter name and touch Login Button to close Login Activity & open
HomeActivity
○ Send name to HomeActivity
○ Clear field name if minimize and re-open app
● Create HomeActivity:
○ Get name from LoginActivity and show it on screen
○ Press CLOSE button to finish app
References
● https://google-developer-training.github.io/android-developer-fun
damentals-course-concepts-v2/