intent android club 2015. agenda intent class explicit activation implicit activation
TRANSCRIPT
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: example
• Intent intent = new Intent();• intent.setAction(Intent.ACTION_DIAL);• startActivity(intent);
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: example 3
• Intent intent = new Intent(Intent.ACTION_VIEW);intent.setData(Uri.parse("http://google.com"));startActivity(intent);
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: 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
Homework 1: extra
• Create ActivityA• Create ActivityB• Put 2 EditTexts: username and
password• Pass username and password to
ActivityB• Show them in TextViews
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