Intent 意图简单使用实现页面跳转
2016-09-20 10:10
375 查看
隐式意图::在开启目标activity时没有指定目标activity的名称,而是通过指定一组动作、数据、类型,让系统自动的在清单文件中匹配目标activity,然后启动它。
Intent:意图,做一件事情的想法;Intent: 包含动作和目标数据;
Intent: 的作用:激活组件和传递参数;
模版代码:
跳转到第二个界面 Intent intent = new Intent(); //设置动作:目标activity在清单文件中配置的action的值 intent.setAction("<span style="color:#ff0000;">com.itheima.SECONDE</span>"); //设置数据:目标activity在清单文件中配置的data的值,且必须在此处写Scame的值:比如: Scame//任意字符串 intent.setData(Uri.parse("<span style="font-family: 微软雅黑; font-size: 14px; line-height: 21px; widows: auto;"><span style="color:#ff0000;">http://www.sohu.com/image</span></span>")); //设置类型:目标activity在清单文件中配置的category的值 intent.addCategory("android.intent.category.DEFAULT"); //打开目标界面,启动目标activity startActivity(intent);
<div style="font-family: 微软雅黑; font-size: 14px; line-height: 21px; widows: auto;"> <pre name="code" class="java"> 跳转到第二个界面的配置:
<div style="font-family: 微软雅黑; font-size: 14px; line-height: 21px; widows: auto;"> * 对于新建的Activity文件进行配置时,需要:</div><div style="font-family: 微软雅黑; font-size: 14px; line-height: 21px; widows: auto;"> * 1. 自定义activity里面的name属性----->自定义一个字符串即可:com.exemple.SECONDE</div><div style="font-family: 微软雅黑; font-size: 14px; line-height: 21px; widows: auto;"> * 2. category属性都改成DEFAULT</div><div style="font-family: 微软雅黑; font-size: 14px; line-height: 21px; widows: auto;"> * 3. 每一个新建的Activity都有对应的布局文件--activity-seconde.xml</div><div style="font-family: 微软雅黑; font-size: 14px; line-height: 21px; widows: auto;"> * 4. activity里面的name属性值是activity文件的全类名</div><div style="font-family: 微软雅黑; font-size: 14px; line-height: 21px; widows: auto;"> * 5. activity里面的lable属性是界面名称--比如:第二个界面 </div>
<activity android:name="com.example.moreActivity.SecondActivity" android:label="第二个界面" > <intent-filter> <action android:name="<span style="color:#ff0000;">com.exemple.SECONDE</span>" /> <span style="white-space:pre"> </span><<span style="color:#ff0000;">data android:scheme="http" android:host="www.sohu.com" android:path="/image</span>" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
应用场景:打开另外一个应用程序中的界面;
显示意图: 在开启目标activity时指定了activity的名称。
<span style="font-weight: normal;"> <span style="font-size:12px;">模版代码: //使用显式意图打开界面 //跳转到第二个界面 //context 上下文对象 //class 目标activity的class Intent intent = new Intent(this, SecondActivity.class); //打开目标界面,启动目标activity startActivity(intent); 应用场景:打开本地应用程序中的界面;</span></span>
<span style="font-weight: normal;"><span style="font-size:12px;"> </span></span>
<span style="font-weight: normal;"><span style="font-size:12px;"> 使用显式意图打开界面的速度快,隐式意图打开的速度慢</span></span>
相关文章推荐
- 使用storyboard实现页面跳转,简单的数据传递
- (4.4.1)使用storyboard实现页面跳转,简单的数据传递
- 使用storyboard实现页面跳转,简单的数据传递
- 【iOS界面处理】使用storyboard实现页面跳转,简单的数据传递
- (4.4.1)使用storyboard实现页面跳转,简单的数据传递
- [转]使用storyboard实现页面跳转,简单的数据传递
- 【iOS界面处理】使用storyboard实现页面跳转,简单的数据传递
- Android入门(8)——使用Intent实现页面跳转
- Android成长日记-使用Intent实现页面跳转
- 使用storyboard实现页面跳转,简单的数据传递(转载)
- 安卓四大组件之一#2-一使用Intent显式意图实现界面跳转以及数据传递
- Intent实现A页面跳转到B页面,通过意图由A界面传递对象及对象列表的详解
- 使用storyboard实现页面跳转,简单的数据传递
- iOS中使用storyboard实现页面跳转,Segue详解及简单的数据传递
- 【iOS界面处理】使用storyboard实现页面跳转,简单的数据传递
- 使用storyboard实现页面跳转,简单的数据传递
- 【iOS界面处理】使用storyboard实现页面跳转,简单的数据传递
- 使用storyboard实现页面跳转,简单的数据传递
- 使用storyboard实现页面跳转,简单的数据传递
- (4.4.1)使用storyboard实现页面跳转,简单的数据传递