现在的位置: 首页 > 综合 > 正文

[android]Intent意图

2013年11月23日 ⁄ 综合 ⁄ 共 1210字 ⁄ 字号 评论关闭

Intent---用于组件之间的跳转和数据传输


显示意图:---明确指出了目标组件的名称--需要知道组件的名称,更多应用在程序内部

Intent intent=new Intent(); intent.setClass(Context context,***.class);

Intent intent=new Intent(Context context,***.class);

ComponentName name=new CompoentName(Context context,***.class);

   Intent intent=new Intent(); intent.setComponentName(name);


意图的属性:

action---对执行动作的描述,String类型,

data---对执行动作所要操作的数据的描述,android中采用Uri来表示数据

component---组件,显示指定Intent的目标组件名称

extra---附加信息,除了data外,还可以通过extra添加附加信息,extra属性使用Bundle类型进行数据传递

            putExtra(String key,value)---value类型:基本数据类型、基本类型数组、String String[] 、可序列化对象,bundle

flag---


隐式意图:---未明确指出目标组件的名称---使用Intent-filter
来寻找与其相关的对象---广泛用于不同程序之间的传递

Intent intent=new Intent();

intent.setAction();---设置action,发送一种类型的action,可以让所有支持该类型的activity都收到


隐式意图的过滤:

action:

  intent对象中最多只能有一个action

  intent-filter中可以声明多个action

  如果intent中包含的action,在filter中也有声明,通过测试

  如果intent-filter中未声明action,该filter拒绝任何测试

  如果intent-filter中未声明action,intent中也不包含任何action,通过测试

category:

  intent中可以包含0到多个category

  intent-filter中可以包含0到多个category

  如果intent中声明的category是intent-filter中声明的category的子集,通过测试

  对于传到setActivity()中的intent,会自动为其追加一个category:android.intent.category.DEFAULT

data(Uri):

http:www.163.com:8080/index.jsp

scheme:http---协议

host:www.163.com---主机

port:8080---端口

path:index.jsp---路径



抱歉!评论已关闭.