I'm trying to follow this tutorial:
http://www.vogella.com/articles/AndroidCalendar/article.html
I understand what putExtra does
but I fail to understand what setData() means?
Android Docs, wasn't much helpful:
Set the data this intent is operating on.
what does this mean for the constant
intent.setData(CalendarContract.Events.CONTENT_URI);
?
There doesn't seem to be any affect when I comment out this line.
Intents are asynchronous messages which allow Android components to request functionality from other components of the Android system. For example an Activity can send an Intents to the Android system which starts another Activity . putExtra() adds extended data to the intent.
setData() is used for the Android System to find an application component that matches the data attribute in implicit intent.
Using putExtra() We can start adding data into the Intent object, we use the method defined in the Intent class putExtra() or putExtras() to store certain data as a key value pair or Bundle data object. These key-value pairs are known as Extras in the sense we are talking about Intents.
setType(String mimeType) input param is represent the MIME type data that u want to get in return from firing intent(here myIntent instance). by using one of following MIME type you can force user to pick option which you desire. Please take a Note here, All MIME types in android are in lowercase.
setData()
is used to point to the location of a data object (like a file for example), while putExtra()
adds simple data types (such as an SMS text string for example).
Here are two examples to clarify:
setData()
used here to set the location of a file that you want to share.
File fileToShare = new File("/sdcard/somefile.dat"); Intent i = new Intent(); i.setAction(Intent.ACTION_SEND); i.setData(Uri.fromFile(fileToShare)); startActivity(i);
putExtra()
is used here to set the text content that you want to share.
Intent i = new Intent(); i.setAction(Intent.ACTION_SEND); String textBodyString = "some text"; i.putExtra(Intent.EXTRA_TEXT, textBodyString); i.setType(HTTP.PLAIN_TEXT_TYPE);
For more information I suggest some readings about Intents and the setData()
, setType()
and setDataAndType()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With