Top Banner
Intent Android Club 2015
35

Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Dec 29, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Intent

Android Club 2015

Page 2: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Agenda

• Intent class• Explicit activation• Implicit activation

Page 3: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

2 purposes

• Operation to be performed (Send email)

• Event notification (Telegram message came)

Page 4: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

I want to ...

• Select contact• Take photo• Display map

Page 5: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Intent opens ...

• Activity which can do that operation

Page 6: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Intent fields

• Action – desired operation• Data – data associated with intent• Category – additional information• Type – show mime type• Component – exact activity to open• Extras – key-value pair• Flags – flag about how intent handled

Page 7: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Action

• ACTION_DIAL• ACTION_VIEW• ACTION_SEND• ACTION_MAIN

Page 8: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Action: example

• Intent intent = new Intent();• intent.setAction(Intent.ACTION_DIAL);• startActivity(intent);

Page 9: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Data

• Data associated with intent• URI(geo, tel, http)

Page 10: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Data: example

• Intent intent = new Intent(Intent.ACTION_VIEW);intent.setData(Uri.parse("geo:0.0,0.0"));startActivity(intent);

Page 11: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Data: practice

• Create application which opens Tashkent in Google Maps

• Latitude: 41.2667• Longitude: 69.2167

Page 12: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Data: example 2

• Intent intent = new Intent();• intent.setAction(Intent.ACTION_DIAL);• Intent.setData(Uri.parse(“tel:

+998903735173”);• startActivity(intent);

Page 13: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Data: practice 2

• Create application which dials your best friends number

Page 14: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Data: example 3

• Intent intent = new Intent(Intent.ACTION_VIEW);intent.setData(Uri.parse("http://google.com"));startActivity(intent);

Page 15: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Data: practice 3

• Create application which opens Facebook website

Page 16: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Category

• Additional information about Intent• CATEGORY_BROWSABLE• CATEGORY_LAUNCHER

Page 17: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Type

• Specifies MIME type of Intent• image/png, image/jpg• text/html, text/html• setType()• emailIntent.setType("text/html");

Page 18: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Type: example

• final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

• emailIntent.setType("text/html"); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); startActivity(intent);

Page 19: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Component

• Intent intent = new Intent(MainActivity.this, ActivityB.class);

• startActivity(intent);

Page 20: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Component: practice

• Create ActivityA• Create ActivityB• Put button on ActivityA which opens

ActivityB

Page 21: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Extra

• Key-value pair• Intent intent = new Intent(A.this,

B.class);• intent.putExtra(“parol”,”1234”);• startActivity(intent);

Page 22: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Extra: practice

• Create ActivityA• Create ActivityB• Put button which sends “secret

information” to ActivityB• Secret information: We are members

of Android Club• Show secret information in ActivityB

Page 23: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Flags

• How intent should be handled• FLAG_ACTIVITY_NO_HISTORY• FLAG_ACTIVITY_NO_ANIMATION

Page 24: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Flags: example

• Intent intent = new Intent(MainActivity.this, ActivityB.class);intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);startActivity(intent);

Page 25: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Flags: practice

• Create ActivityA• Create ActivityB• Create ActivityC• Put button on A which opens B• Put button on B which opens C and

close A and C

Page 26: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Activation

• Explicit (Явный)• Implicit (Неявный)

Page 27: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Implicit activation

• A) Calling activity• B) IntentFilter

Page 28: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Intent resolution

• ACTION• DATA• CATEGORY

Page 29: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Homework 1: extra

• Create ActivityA• Create ActivityB• Put 2 EditTexts: username and

password• Pass username and password to

ActivityB• Show them in TextViews

Page 30: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Homework2: flag

• Create ActivityA• Create ActivityB• Open ActivityB without animation

Page 31: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Homework3: implicit activation

• Create ActivityA• From ActivityA, startActivity with

ACTION_DIAL intent• Create ActivityB• Define <intent-filter> for ActivityB

Page 32: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Homework4: implicit activation

• Create ActivityA• From ActivityA, startActivity with

EMAIL_APP(category) intent• Create ActivityB• Define <intent-filter> for ActivityB

Page 33: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Homework: Action+Data:

• Try to put ACTION_CALL instead of ACTION_DIAL

• Tell me what is difference?• Do not forget to add

android.permission.CALL_PHONE

Page 34: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Questions?

• Any questions?

Page 35: Intent Android Club 2015. Agenda Intent class Explicit activation Implicit activation.

Thank you

• Thank you for your attention!