1、基于消息的通信机制 Intent------bundle,extra
用这种方式一般而言,传递一些简单的类型是比较容易的,例如int,string等
详细介绍下Intent机制
Intent包含两部分:
1)目的【action】------要去到哪里去
2)内容【category、data】------路上带些什么,区分性数据和内容性数据
简单数据传递:
用这种方式一般而言,传递一些简单的类型是比较容易的,例如int,string等
详细介绍下Intent机制
Intent包含两部分:
1)目的【action】------要去到哪里去
2)内容【category、data】------路上带些什么,区分性数据和内容性数据
简单数据传递:
这里以ActivityA向ActivityB传递数据为例
Intent intent = new Intent(context, ActivityB.class);
//如果context上下文不是Activity的话, 需要添加下面这个flag
if (!(context instanceof Activity)) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
//添加要传递的数据
intent.putExtra(key, value);
//或则将数据打包进Bundle里
Bundle bundle = n