1、 Intent 和 Service BoardCastReceiver
2、 Intent具有将在不同应用程序间的代码绑定在运行时的后期。它是最重要的使用在发布Activity,也可以用用来连接两个Activity。
3、 Intent是一个基本的被动的数据结构用来保存将要执行动作的抽象描述,在Intent中将包含action、data和category、component、extras、
4、 一些数据类型,如下表:
Activity Actions | ||||||||
ACTION_MAIN | 启动一个主入口点,不期望接受数据 | |||||||
ACTION_VIEW | 将数据呈现给用户,可以用来对数据进行恢复 | |||||||
ACTION_ATTACH_DATA | 被用来指示一些应该依附在其他地方的数据 | |||||||
ACTION_EDIT | 提供一种显示可编辑的访问已给的数据 | |||||||
ACTION_PICK | ||||||||
ACTION_CHOOSER | ||||||||
ACTION_GET_CONTETN | ||||||||
ACITON_DIAL | ||||||||
ACTION_CALL | ||||||||
ACTION_SEND | ||||||||
ACTION_SENDTO | ||||||||
ACTION_ANSWER | ||||||||
ACTION_INSERT | ||||||||
ACTION_DELETE | ||||||||
ACTION_RUN | ||||||||
ACTION_SYNC | ||||||||
ACTION_PICK_ACTIVITY | ||||||||
Broadcast Actions | ||||||||
ACTION_TIME_PICK | ||||||||
ACTION_TIEM_CHANGED | ||||||||
ACTION_TIMERZONE_CHANGED | ||||||||
ACTION_BOOT_COMPLETED | ||||||||
ACTION_PACKAGE_ADDED | ||||||||
ACTION_PACKAGE_CHANEGED | ||||||||
ACTION_PACKAGE_RESTARTED | ||||||||
ACTION_PACKAGE_DATA_CLEARED | ||||||||
ACTION_UID_REMOVED | ||||||||
ACTION_BATTERY_CHANGED | ||||||||
ACTION_POWER_CONNECTED | ||||||||
ACTION_POWER_DISCONNECTED | ||||||||
ACTION_SHUTDOWN | ||||||||
Standard Categories | ||||||||
CATEGORY_DEFAULT | activity should be an option for the default action (center press) to perform on a piece of data | |||||||
CATEGORY_BROWSABLE | Activities that can be safely invoked from a browser must support this category | |||||||
CATEGORY_TAB | ||||||||
CATEGORY_ALTERNATIVE | Set if the activity should be considered as an alternative action to the data the user is currently viewing | |||||||
CATEGORY_SELECTED_ALTERNATIVE | ||||||||
CATEGORY_LAUNCHER | Should be displayed in the top-level launcher | |||||||
CATEGORY_INFO | Provides information about the package it is in | |||||||
notepad++CATEGORY_HOME | This is the home activity, that is the first activity that is displayed when the device boots. | |||||||
CATEGORY_PREFERENCE | ||||||||
CATEGORY_TEST | To be used as a test (not part of the normal user experience). | |||||||
CATEGORY_CAR_DOCK | An activity to run when device is inserted into a car dock | |||||||
CATEGORY_DEST_DOCK | ||||||||
CATEGORY_LE_DESK_DOCK | activity to run when device is inserted into a analog (low end) dock | |||||||
CATEGORY_HE_DESK_DOCK | An activity to run when device is inserted into a digital (high end) dock | |||||||
CATEGORY_CAR_MODE | Used to indicate that the activity can be used in a car environment. | |||||||
CATEGORY_APP_MARKEDT | This activity allows the user to browse and download new applications | |||||||
Standard Extra Data | ||||||||
EXTERA_ALARM_COUNT | ||||||||
EXTERA_EMAIL | ||||||||
EXTERA_KEY_EVENT | ||||||||
EXTERA_INTENT | ||||||||
EXTERA_STREAM | ||||||||
EXTERA_TEXT | ||||||||
EXTERA_TITLE | ||||||||
EXTERA_UID | ||||||||
5、 举个例子来解读在Manifest文件中Intent功能的定义
6、 <manifest xmlns:android="schemas.android/apk/res/android"
package="pad">
<application android:icon="@drawable/app_notes"
android:label="@string/app_name">
<provider class=".NotePadProvider"
android:authorities="le.provider.NotePad" />
<activity class=".NotesList" android:label="@string/title_notes_list">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
package="pad">
<application android:icon="@drawable/app_notes"
android:label="@string/app_name">
<provider class=".NotePadProvider"
android:authorities="le.provider.NotePad" />
<activity class=".NotesList" android:label="@string/title_notes_list">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.dir/" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/" />
</intent-filter>
</activity>
<activity class=".NoteEditor" android:label="@string/title_note">
<intent-filter android:label="@string/resolve_edit">
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.dir/" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/" />
</intent-filter>
</activity>
<activity class=".NoteEditor" android:label="@string/title_note">
<intent-filter android:label="@string/resolve_edit">
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.INSERT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.dir/" />
</intent-filter>
</activity>
<activity class=".TitleEditor" android:label="@string/title_edit_title"
android:theme="@android:style/Theme.Dialog">
<intent-filter android:label="@string/resolve_title">
<action android:name="android.intent.action.EDIT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.INSERT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.dir/" />
</intent-filter>
</activity>
<activity class=".TitleEditor" android:label="@string/title_edit_title"
android:theme="@android:style/Theme.Dialog">
<intent-filter android:label="@string/resolve_title">
<action android:name="pad.action.EDIT_TITLE" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.ALTERNATIVE" />
<category android:name="android.intent.category.SELECTED_ALTERNATIVE" />
<data android:mimeType="vnd.android.cursor.item/" />
</intent-filter>
</activity>
</application>
</manifest>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.ALTERNATIVE" />
<category android:name="android.intent.category.SELECTED_ALTERNATIVE" />
<data android:mimeType="vnd.android.cursor.item/" />
</intent-filter>
</activity>
</application>
</manifest>
7、 在这个文件中有三个Activity,现在就三个文件中的Intent定义的定义进行解读
第一个activity:serves as our main entry into the app.(作为程序的主入口)
Given these capabilities, the following intents will resolve to the NotesList activity:
{ action=android.app.action.MAIN } matches all of the activities that can be used as top-level entry points into an application.
{ action=android.app.action.MAIN, category=android.app.category.LAUNCHER } is the actual intent used by the Launcher to populate its top-level list.
{ action=android.intent.action.VIEW data=content://le.provider.NotePad/notes } displays a list of all the notes under "content://le.provider.NotePad/notes", which the user can browse through and see the details on.
{ action=android.app.action.PICK data=content://le.provider.NotePad/notes } provides a list of the notes under "content://le.provider.NotePad/notes", from which the user can pick a note whose data URL is returned back to the caller.
{ action=android.app.action.GET_CONTENT type=vnd.android.cursor.
} is similar to the pick action, but allows the caller to specify the kind of data they want back so that the system can find the appropriate activity to pick something of that data type.
第二个Activity:shows the user a single note entry and allows them to edit it.(显示每个日志的入口并且可以编辑)
{ action=android.intent.action.VIEW data=content://le.provider.NotePad/notes/{ID} } shows the user the content of note {ID}.
{ action=android.app.action.EDIT data=content://le.provider.NotePad/notes/{ID} } allows the user to edit the content of note {ID}.
{ action=android.app.action.INSERT data=content://le.provider.NotePad/notes } creates a new, empty note in the
notes list at "content://le.provider.NotePad/notes" and allows the user to edit it. If they keep their changes, the URI of the newly created note is returned to the caller
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论