目录:
Intent对于Android应用的作用
使用Intent启动系统组件 Intent的Component属性的作用 Intent的Action属性的作用 Intent的Category属性的作用 为指定Action,Category 的Intent配置对应的intent-filter Intent的Data属性 Intent的Type属性 为指定Data,Type的Intent配置对应的intent-filter Intent的Extra属性 Intent的Flag属性 使用Intent创建Tab页
对于Intent的理解
Intent是意图的意思 Android用Intent来封装自己的调用意图 启动Activity,Service,BroadcastReceiver,都用统一的Intent来封装启动意图 使用Intent提供了统一的编程模型 使用Intent可以实现解耦 1 Intent封装了启动某个组件的意图 2 Intent是组件之间进行通信的媒介,两个组件把需要交换的数据封装成Bundle,再用Intent来携带这个数据,就实现了数据的交换
Intent 属性 作用 Category —–: Extra 携带需要传递的数据 flag —–: Type —–: Action —–: Component 明确指定要启动的组件 —–:
startActivity(new Intent(MainActivity.this ,SecondActivity.class ));
总结
new Intent();
new Intent(Intent intent);
new Intent(String action);
new Intent(Context packageContext, Class <?> cls);
new Intent(String action,Uri uri);
new Intent(String action, Uri uri, Context packageContext,Class <?> cls);
Data,Type的intent-filter配置
Data向Action提供操作的数据 Data接受一个Uri对象 一个Uri对象通过如下形式的字符串表示: content://com.android.contacts/1 Type用于指定该Data所指定的Uri的MIME类型 MIME类型可以是任何自定义的类型,只要符合abc/xyz的格式的字符串即可? Data和Type两个属性会相互覆盖,如果不想两者互相覆盖,就设置setDataAndType属性
疑问
如果利用Intent和IntentFilter进行通信 Data向Action提供操作的数据?