Android开发讲义第五章Intent与IntentFil.ppt

上传人:max****ui 文档编号:3386175 上传时间:2019-12-13 格式:PPT 页数:19 大小:490KB
返回 下载 相关 举报
Android开发讲义第五章Intent与IntentFil.ppt_第1页
第1页 / 共19页
Android开发讲义第五章Intent与IntentFil.ppt_第2页
第2页 / 共19页
Android开发讲义第五章Intent与IntentFil.ppt_第3页
第3页 / 共19页
点击查看更多>>
资源描述
Android开发讲义,主讲人:,Android开发环境的搭建Android初级界面编程事件处理深入ActivityIntent与IntentFilterAndroid高级界面编程Android应用的资源,Android开发讲义,图形与图象处理Android数据存储技术与数据共享Service与BroadcastReceiverAndroid网络应用多媒体应用开发OpenGL与3D应用开发传感器应用开发,Android开发讲义,GPS应用开发GoogleMap服务项目实战,Android开发讲义,Intent对象详解Intent的属性及intent-filter配置使用Intent创建Tab页面,Android开发讲义,当一个Activity需要启动另一个Activity时,程序并没有直接告诉系统要启动哪个Activity,而是通过Intent来表达自己的意图:需要启动哪个Activity。“Intent”的中文翻译就是“意图”的意思。Android使用Intent来封装程序的“调用意图”,不管程序想启动一个Activity也好,想启动一个Service组件也好,想启动一个BroadcastReceiver也好,Android使用统一的Intent对象来封装这种“启动意图”,很明显使用Intent提供了一致的编程模型。使用Intent的另一个好处:在某些时候,应用程序只是想启动具有某种特征的组件,并不想和某个具体的组件耦合,所以这样就会降低与组件间的耦合度。总之,Intent封装Android应用程序需要启动某个组件的“意图”。不仅如此,Intent还是应用程序组件之间通信的重要媒介。,Android开发讲义,一Intent对象详解Android的应用程序包含三种重要组件:Activity、Service、BroadcastRecevier,应用程序采用了一致的方式来启动它们,就是依靠Intent来进行启动的,Intent就封装了想要启动程序的意图,不仅如此,Intent还可用于与被启动组件交换信息。,Android开发讲义,本节课仅以Activity为例,二Intent的属性及Intent-filter配置1.Component属性在上一章中通过了简化的语句来设定要启动的目标Activity,在此可以通过Component属性来设定启动的目标Activity。ComponentNamecomp=newConponentName(res.this,target.class);,Android开发讲义,当前类,目标类,使用Intent中的Component属性(原类)示例publicvoidonCreate(BundlesavedInstanceState)super.onCreate(savedInstanceState);setContentView(R.layout.main);ButtonfinishBtn=(Button)findViewById(R.id.finish);finishBtn.setOnClickListener(newOnClickListener()publicvoidonClick(Viewv)ComponentNamecomponent=newComponentName(DemoActivity.this,SecondActivity.class);Intentintent=newIntent();intent.setComponent(component);startActivity(intent););,Android开发讲义,使用Intent中的Component属性(目标类)示例protectedvoidonCreate(BundlesavedInstanceState)super.onCreate(savedInstanceState);setContentView(R.layout.second);EditTexttxt=(EditText)findViewById(R.id.txt);Intentintent=getIntent();ComponentNamecomponent=intent.getComponent();txt.setText(packageName:+component.getPackageName()+n+className:+component.getClassName();,Android开发讲义,二Intent的属性及Intent-filter配置2.Action、Category属性与intent-filter配置Intent的Action、Category属性都是一个普通的字符串,其中Action代表该Intent所要完成的一个抽象“动作”,而Cateory则用于为Action增加额外的附加信息。通常Action属性会与Category属性结合使用。Action要完成的只是一个抽象的动作,这个动作具体由哪个组件来完成Action这个字符串本身并不管。,Android开发讲义,针对于Struts2来讲,Action处理用户请求结束后,Action并不会直接指定“跳转”到哪个Servlet,Action的处理方法只是返回一个普通字符串,然后在配置文件中配置该字符串对应到哪个Servlet。采用这种思路就是为了把Action与呈现视图的Servlet分离开。类似的,Intent通过指定Action属性,就可以把该Intent与具体的Activity分离,从而提供高层次的解耦。,Action属性举例(主类)示例publicfinalstaticStringDEMO_ACTION=com.android.action.DEMO_ACTION;publicvoidonCreate(BundlesavedInstanceState)super.onCreate(savedInstanceState);setContentView(R.layout.main);ButtonfinishBtn=(Button)findViewById(R.id.bn);finishBtn.setOnClickListener(newOnClickListener()publicvoidonClick(Viewv)Intentintent=newIntent();intent.setAction(DemoActivity.DEMO_ACTION);startActivity(intent););,Android开发讲义,非硬编码方式,而简单定了字符串,该字符串与配置文件中的action属性相对应,Action属性举例(跳转的目标类)示例publicvoidonCreate(BundlesavedInstanceState)super.onCreate(savedInstanceState);setContentView(R.layout.second);EditTextshow=(EditText)findViewById(R.id.show);/获取该Activity对应的Intent的Action属性Stringaction=getIntent().getAction();/显示Action属性show.setText(Action为:+action);,Android开发讲义,Action属性举例(配置文件)示例,Android开发讲义,在目标类中定义action元素,跳转的目标类,Category属性举例(主类)示例publicfinalstaticStringDEMO_ACTION=com.android.action.DEMO_ACTION;publicfinalstaticStringDEMO_CATEGORY=com.android.category.DEMO_CATEGORY;publicvoidonCreate(BundlesavedInstanceState)super.onCreate(savedInstanceState);setContentView(R.layout.main);ButtonfinishBtn=(Button)findViewById(R.id.bn);finishBtn.setOnClickListener(newOnClickListener()publicvoidonClick(Viewv)Intentintent=newIntent();intent.setAction(DemoActivity.DEMO_ACTION);intent.addCategory(DemoActivity.DEMO_CATEGORY);startActivity(intent););,Android开发讲义,定义Action与Category属性,Category属性举例(配置文件)示例,Android开发讲义,定义category属性,二Intent的属性及Intent-filter配置3.指定Action、Category调用系统Activity实际上Android内部提供了大量标准的Action、Catetory常量来供开发者使用。实例:1.查看、并获取联系人电话2.返回系统Home桌面该功能实例放到以后讲解,Android开发讲义,二Intent的属性及Intent-filter配置4.Data、Type属性与intent-filter配置暂略,Android开发讲义,二Intent的属性及Intent-filter配置5.Extra属性暂略,Android开发讲义,
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 课件教案


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!