Intent(意图),顾名思义就是一个组件传递出意图,另一个组件去执行这个意图,不同组件通信的载体。
Intent的常用情况:
1.启动Activity: startActivity(Intent intent)
2.启动Service:startService(Intent intent)
3.停止Service:stopService(Intent intent)
4.绑定Service:bindService(Intent intent)
5.发送广播: sendBroadcast(Intent intent)
Intent的属性:
1.action: 要执行的动作
2.category: 要执行动作的分类
3.type: 要执行动作处理的数据类型
4.data/extra: 要执行动作处理的数据
5.component:要执行动作的具体执行者类名(类似于Intent里直接指定类名)
总结:
显示意图:如果明确知道执行者的类名,就在Intent里直接指定类名。
隐式意图:如果不知道执行者的类名,就使用action、category、type去寻找具体执行者。