Lesson 4 - Intents Flashcards
Intents
messaging objects; let an app request that an action take place; e.g. start new activity, display photo, make a call, etc.
Intents metaphor
“envelopes”; who (which component) to send to, bit of data - packaged as EXTRAs (primitive tuples)
explicit intent
includes name of target component
add activity how?
dropdown menu for new activity, or file->new file
add data to intent how?
put extra; stuffs data into intent
putExtra() data retrieved how?
key, value; like JSON. putExtra(String name, String value)
putExtra() String, String example
startChildActivityIntent.putExtra(Intent.EXTRA_TEXT, textEntered);
how to get intent that created this activity; “get envelope”
getIntent();
get string out of Intent; “open envelope”
getStringExtra(String name)
explicit intent is?
where we know exactly what activity to start
how to make explicit intent?
Intent(context, classOfActivityToStart)
implicit intent is?
where we don’t know or care how our request will be fulfilled
how to find examples of most used intents?
“common intents”
URI?
like an address to data
intent to launch website?
Intent(Intent.ACTION_VIEW, webpageUri)
URI template
scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
media type
2 part identifier for content on internet
media type information
type, subtype, optional parameters
media type text example
text, html, charset=UTF8
ShareIntent.IntentBuilder syntax
ShareIntent.IntentBuilder .from(this) .setChooserTitle(title0 .setType(mimeType) .setText(text) .startChooser();
.startChooser();
IntentBuilder is basically a helper class for constructing sharing intents(Intent#ACTION_SEND and Intent#ACTION_SEND_MULTIPLE) and starting activities to share content.
also is there any other differences between these two functions
Under the hood, both startChooser() and startActivity() perform same action. startChooser() just wraps startActivity().