Intent
Intent:一个表示“启动意图”的对象
Activity : getIntent()获取当前Activity唯一Intent
显式调用Intent
Component
Intent intent =newIntent();
ComponentName comp =newComponentName(MainActivity.this,SecondActivity.class);
intent.setComponent(comp);
startActivity(intent);
Intent intent =newIntent();
intent.setclass(MainActivity.this,SecondActivity.class);
startActivity(intent);
隐式调用Intent
Intent指定属性值(子集) ∈ <intent-filter>指定属性值(父集)
<intent-filter>:
多个<action.../>
多个<category.../>
多个<data.../>
|
Intent:
addCategory(String):多个Category
addFlags(int) setFlag(int)
setAction(String):一个Action
setClass
setType
|
Action Category
Intent intent =newIntent();
intent.setAction(SOME_STRING);
startActivity(intent);
Intent 对象中默认有category: android.intent.category.DEFAULT
action至少选一匹配;category须全匹配
<intent-filter>
<action android:name="SOME_STRING"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
Data Type
intent | <intent-filter> |
setData(uri) 匹配顺序:scheme>> host>>port、path |
|
setType(String mime) | <data android:mimeType=""/> |
data至少选一匹配
先后setData(uri) setType(String mime) 会相互覆盖
同时:setDataAndType(Uri data, String type)
A .mim or .mme file is a file in the Multipurpose Internet Mail Extension (MIME) format.
MIME is a specification for the format of non-text e-mail attachments(附件) that allows the attachment to be sent over the Internet. MIME allows your mail client or Web browser to send and receive things like spreadsheets and audio, video and graphics files via Internet mail.
Extra
putExtra(Bundle) | puExtra(String key,Xxx value) |
Bundle getExtra() | getXxxExtra(String key) |
Bundle:
putXxx(String key,Xxx value) putSerializable(String key,Serializable data) |
getXxx(String key,Xxx defaultValue) |
Flag
Set special flags controlling how this intent is handled.
Most values here depend on the type of component being executed by the Intent, specifically the FLAG_ACTIVITY_* flags are all for use with Context.startActivity() and the FLAG_RECEIVER_* flags are all for use with Context.sendBroadcast().
etc.
FLAG_ACTIVITY_BROUGHT_TO_FRONT
FLAG_ACTIVITY_CLEAR_TASK
FLAG_ACTIVITY_CLEAR_TOP
FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS