intent android club 2015. agenda intent class explicit activation implicit activation

35
Intent Android Club 2015

Upload: ferdinand-turner

Post on 29-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Intent

Android Club 2015

Agenda

• Intent class• Explicit activation• Implicit activation

2 purposes

• Operation to be performed (Send email)

• Event notification (Telegram message came)

I want to ...

• Select contact• Take photo• Display map

Intent opens ...

• Activity which can do that operation

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

Action

• ACTION_DIAL• ACTION_VIEW• ACTION_SEND• ACTION_MAIN

Action: example

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

Data

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

Data: example

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

Data: practice

• Create application which opens Tashkent in Google Maps

• Latitude: 41.2667• Longitude: 69.2167

Data: example 2

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

+998903735173”);• startActivity(intent);

Data: practice 2

• Create application which dials your best friends number

Data: example 3

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

Data: practice 3

• Create application which opens Facebook website

Category

• Additional information about Intent• CATEGORY_BROWSABLE• CATEGORY_LAUNCHER

Type

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

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);

Component

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

• startActivity(intent);

Component: practice

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

ActivityB

Extra

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

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

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

Flags

• How intent should be handled• FLAG_ACTIVITY_NO_HISTORY• FLAG_ACTIVITY_NO_ANIMATION

Flags: example

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

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

Activation

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

Implicit activation

• A) Calling activity• B) IntentFilter

Intent resolution

• ACTION• DATA• CATEGORY

Homework 1: extra

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

password• Pass username and password to

ActivityB• Show them in TextViews

Homework2: flag

• Create ActivityA• Create ActivityB• Open ActivityB without animation

Homework3: implicit activation

• Create ActivityA• From ActivityA, startActivity with

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

Homework4: implicit activation

• Create ActivityA• From ActivityA, startActivity with

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

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

Questions?

• Any questions?

Thank you

• Thank you for your attention!