Intent 用法总结
来源:互联网 发布:php网页小游戏源码 编辑:程序博客网 时间:2024/05/01 10:58
intent 目的 意图。可以来启动activity,启动service,发送Broadcast。
显示意图
常用来启动本应用内的活动或者服务
startActivity(new Intent(main.this,intent.class));//启动活动startService(new Intent(main.this,intent.class));//启动服务
隐式意图
常用来启动其他应用
在AndroidManifest.xml配置要启动的活动
<activity android:name=".SecondActivity" > <intent-filter> <action android:name="com.example.activitytest.ACTION_START" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter></activity>
在 标 签 中 我 们 指 明 了 当 前 活 动 可 以 响 应 com.example.activitytest.ACTION_START 这个 action,而标签则包含了一些附加信息,更精确地指明了当前的活动能够响应的 Intent 中还可能带有的 category。只有和中的内容同时能够匹配上 Intent 中定的 action 和 category 时,这个活动才能响应该 Intent。
new一个Intent来启动活动
Intent intent = new Intent("com.example.activitytest.ACTION_START");intent.addCategory("com.example.activitytest.MY_CATEGORY");//可以通过这种方式来增加Category属性startActivity(intent);
category是默认的所以不用去设置
发送广播
Intent intent = new Intent( “cn.lenovo.yangguangf ” );
sendBroadcast(intent);
sendOrderedBroadcast(intent, receiverPermission);//有序广播,不太懂receiverPermission的作用…
在过程中传输数据
Intent intent = new Intent(Intent.ACTION_VIEW);intent.setData(Uri.parse("http://www.baidu.com"));//通过setData来插入数据//通过Intent来安装应用Intent intent = new Intent(Intent.ACTION_VIEW);intent.addCategory(Intent.CATEGORY_DEFAULT);intent.setDataAndType(Uri.fromFile(resultl),"application/vnd.android.package-archive");//还有类型 需要看下它的源码。startActivity(intent);startActivityForResult(intent, 0);// 如果用户取消安装的话,返回的动作。要在当前活动建一个方法//在activtiy中写一个方法。处理返回的事件protected void onActivityResult(int requestCode, int resultCode, Intent data) { enterHome(); super.onActivityResult(requestCode, resultCode, data); }
与此对应,我们还可以在标签中再配置一个标签,用于更精确地指
定当前活动能够响应什么类型的数据。标签中主要可以配置以下内容。
android:scheme
用于指定数据的协议部分,如上例中的 http 或者file部分。
PendingIntent
专门来响应“通知”的点击事件。
Intent intent = new Intent(this, NotificationActivity.class);PendingIntent pi = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);//第四个参数是关于是与点击后的。此参数是点击后取消notification.setLatestEventInfo(this, "This is content title","This is content text", pi);
0 0
- Intent用法总结
- Intent用法总结
- Intent的用法总结
- Android Intent用法总结
- Intent用法简单总结
- android intent 用法总结
- Intent 用法全面总结
- Android Intent 用法总结
- Android:Intent用法总结
- Intent用法总结
- Intent 用法总结
- Intent 用法总结
- Intent的用法总结
- intent用法总结
- Android Intent 常见用法总结
- Android Intent的用法总结
- Android Intent用法全面总结
- Android Intent 用法全面总结
- 只有程序员看的懂面试圣经|如何拿下编程面试
- 通用后台管理系统(ExtJS 4.2 + Spring MVC 3.2 + Hibernate)
- 通过字节流方式实现文件下载以及其中的编码问题
- CTC学习笔记(三) 解码
- Spring Boot / Spring MVC 入门实践 (一) :环境搭建与第一个项目
- Intent 用法总结
- 16个behavior question 的面试官解析及tips
- Lync(Skype)接口开发实录
- uva 455 Periodic Strings
- new与delete创建对象
- nginx负载均衡详细配置
- 安卓学习之—自定义ProgressBar的样式
- poj1837 Balance (二维费用背包&&分组背包)
- 数组集合简单操作