Intent from Android Notepad example
action: android.intent.action.PICK
data: content://com.google.provider.NotePad/notes
Asks the activity to display a list of the notes under content://com.google.provider.NotePad/notes. The user can then pick a note from the list, and the activity will return the URI for that item back to the activity that started the NoteList activity.
action: android.intent.action.GET_CONTENT
data type: vnd.android.cursor.item/vnd.google.note
Asks the activity to supply a single item of Note Pad data.
The above is directly from Android Notepad example.
My question is, why have they defined two intent actions that perform the same task?? When will one or the other action be performed?
Also in the code, they have defined
String action = getIntent().getAction();
if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) 开发者_开发问答{
Could someone please clarify, when will an action be set and on ListItemClick how will getAction resolve to either ACTION_PICK or ACTION_GET_CONTENT
Thanks in advance
My question is, why have they defined two intent actions that perform the same task?
They are not the same task. Quoting the documentation for ACTION_GET_CONTENT
:
This is different than ACTION_PICK in that here we just say what kind of data is desired, not a URI of existing data from which the user can pick. A ACTION_GET_CONTENT could allow the user to create the data as it runs (for example taking a picture or recording a sound), let them browser over the web and download the desired data, etc.
When will one or the other action be performed?
When somebody calls startActivity()
with an Intent
containing one of those two actions, plus a content Uri
pointing to this application (in this case).
Could someone please clarify, when will an action be set
It is set in the Intent
used with the startActivity()
call that was used to start the activity.
how will getAction resolve to either ACTION_PICK or ACTION_GET_CONTENT
By executing the code you included in your question.
精彩评论