Reputation: 36664
I see any intent has extra
field and a data
field.
is there any difference between them or it's just a conceptual difference?
Upvotes: 7
Views: 3387
Reputation: 424
Conceptual or label. It's somehow strange. Here data DO NOT really means data. In fact it simply DON'T MEAN CONTENT.
You should use te extra field to pass non URI data (URI, URL, tel number and such things). You may generally use Extra fields, for simple data
Look at developer.android.com description data -- The data to operate on, such as a person record in the contacts database, expressed as a Uri (Uniform Resource Identifier).
extras -- This is a Bundle of any additional information. This can be used to provide extended information to the component. For example, if we have a action to send an e-mail message, we could also include extra pieces of data here to supply a subject, body, etc.
Upvotes: 0
Reputation: 681
I don't thing that the difference is conceptual. The getExtras()
returns a bundle
and getData()
returns a Uri
see documentation.
Usually I approach the Uri
from getData()
to indicate where to operate on. And the extra
field as an Map/Bundle
to put parameters or arguments in for whatever I'm using the intent for.
Upvotes: 0
Reputation: 3034
Data
The URI (a Uri object) that references the data to be acted on and/or the MIME type of that data. The type of data supplied is generally dictated by the intent's action. For example, if the action is ACTION_EDIT, the data should contain the URI of the document to edit.
Data return URI
Extras
Key-value pairs that carry additional information required to accomplish the requested action. Just as some actions use particular kinds of data URIs, some actions also use particular extras.
Extras contains a Bundle which is an implementation of HashMap to store key values of specific data .
Extra Return Bundle
For more information About Intent extra And Data refer this Url
Upvotes: 11
Reputation:
as mentiond in the documentation of the intent :
the data : is not a content , its a URI , that describe what should be done regarding the specified action .
and the Extras contains a Bundle which is an implementation of HashMap to store key values of specific data .
Upvotes: 0
Reputation: 1367
Data in an intent contains a URI to operate on, such as an URI to email client. And Extras contains the bundle regarding that URI which can carry extra info for data, such as for email client, you can put in subject body etc.
Upvotes: 0
Reputation: 31161
According to the documentation, getData()
returns a Uri
whereas getExtras()
returns a Bundle
. So yes there is a difference and the difference is not just conceptual.
Upvotes: 0