Intent、Binder

Intent

Intent对象大致包含Component、Action、Category、Data、Type、Extra和Flag这7种属性,其中Component用于明确指定需要启动的目标组件,而Extra则用于"携带"需要交换的数据。
需要指出的是,一个Intent对象最多只能包括一个Action属性,程序可调用Intent的setAction(Stringstr)方法来设置Action属性值;但一个Intent对象可以色括多个Category属性,实际上Android内部提供了大量标准的Action、Catetory常量。

Intent最大可传递参数大小为1M,因为其底层是通过Binder实现的。

1. 使用context.startActivity(intent)启动Activity。

2. 使用context.sendBroadCast(intent)广播事件。

    This call is asynchronous; it returns immediately, and you will continue executing while the receivers are run.

    intent不用在界面事件中,界面事件往往是同步的。

3. 使用context.startService(intent)启动服务,context.stopService(intent)停止服务。

4.Intent intent = new Intent();
 intent.putExtra("test_value", "TEST_V");

Bundle bundle = new Bundle();
bundle.putString("test_value", "TEST_V");
 intent.putExtras(bundle);

的区别:

使用Bundle把多个参数又包裹了一层,方便存取。

取参数时注意也不同

bundle.getString(name);
.getIntent().getStringExtra(name);

5.Intent跳转到系统应用中的拨号界面、联系人界面、短信界面及其他。

Binder

Binder是Android系统提供的一种IPC(进程间通信)机制。基于Linux内核还存在其他的IPC机制,例如,管道和Socket等。Binder相对于其它IPC机制更加灵活和方便。

Binder的驱动代码在kerneldrivers/staing/android/binder.c中,该目录下还有一个binder.h头文件。Binder是一个虚拟设备,/proc/binder目录下的内容可用来查看Binder设备的运行状况。
Android系统基本上可以看作是一个基于Binder通信的C/S架构。Binder就像网络一样,把系统的各个部分连接在了一起。在基于Binder通信的C/S架构体系中,除了C/S架构所包括的Client端和Server端外,Android还有一个全局的ServiceManager端,它的作用是管理系统中的各种服务(Service)。
在Android系统的Binder机制中,由4个组件Binder、Client、Server、ServiceManager组成。Client、Server和Service Manager在用户空间中实现,Binder驱动程序在内核空间中实现。

Binder采用AIDL(android interface description language)来描述进程间通信的接口。Binder
作为一个特殊的字符设备,其设备节点是/dev/binder。

内存映射

在Android系统中,当打开Binder设备文件/dev/binder后,需要调用函数mmap把设备内存映射到用户进程地址空间中,这样就可以像操作用户内存那样操作设备内存。在Binder设备中,对内存的映射操作是有限制的,比如Binder不能映射具有写权限的内存区域,最大能映射4MB的内存区域等。在Android系统中,大多数设备本身具有设备映射的设备内存,或者是在驱动初始化时由vmalloc或kmalloc等内核内存函数分配的,在mmap操作时分配Binder的设备内存。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值