Android下intent的setdata、settype和setdataandtype函数
Android中提供了Intent机制来协助应用间的交互与通讯,或者采用更准确的说法是,Intent不仅可用于应用程序之间,也可用于应用程序内部的Activity/Service之间的交互。利用Intent所实现的软件复用的粒度是Activity/Service,比函数复用更高一些,另外耦合也更为松散。
1 settype
使用该函数表示要查找文件的mime类型(如*/*),这个和组件在manifest里定义的相对应,但在源代码里:
view plain copy to clipboard print ?
public Intent setData(Uri data) {
mData = data;
mType = null ;
return this ;
}
view plain
public Intent setData(Uri data) {
mData = data;
mType = null ;
return this ;
}
会将type设为null。
2 setdata
该函数的参数是uri,所以要将数据通过该函数传递时,记得要把数据转化为uri,如Uri.fromFile(new File("/mnt/sdcard/"))。
该函数源代码
view plain copy to clipboard print ?
public Intent setType(String type) {
mData = null ;
mType = type;
return this ;
}
view plain
public Intent setType(String type) {
mData = null ;
mType = type;
return this ;
}
3 所以要同时设置data和type的话只能用函数setdataandtype了
view plain copy to clipboard print ?
public Intent setDataAndType(Uri data, String type) {
mData = data;
mType = type;
return this ;
}
view plain
public Intent setDataAndType(Uri data, String type) {
mData = data;
mType = type;
return this ;
}
作者“quding0308”
相关新闻>>
- 发表评论
-
- 最新评论 更多>>
今日头条
更多>>您可能感兴趣的文章
- android平板上的GridView视图缓存优化
- Android自定义PopupWindow实现的Menu(TabMenu)
- Android开发之Android体系架构介绍
- 自定义ListView背景(解决了拖动变黑的效果)
- Android TextView中设定个别文字字体显示格式
- Android[中级教程]第一章 数据存储之Shared Preferenc
- Android项目代码混淆
- 基于Android NDK的学习之旅-----JNI LOG打印
- Ubuntu 10.10 64bit下使用Android NDK r6编译FFmpeg 0.8.1
- Android开发者指南(2) —— aapt