<span style="color: rgb(90, 90, 90); font-family: "microsoft yahei"; font-size: 25.2px; font-weight: 600; line-height: 27.72px; white-space: pre-wrap; background-color: rgb(255, 255, 255);">一、Intent的定义</span>
1.Intent是一种在不同组件之间传递的请求消息,是应用程序发出的请求和意图。他不仅可以**指明当前组件想要执行的意图**,动作,还可以**在不同组件之间传递数据**。
2.Intent是一种运行时绑定(runtime binding)机制,它能在程序运行的过程中连接两个不同的组件。通过Intent,你的程序可以向Android表达某种请求或者意愿,Android会根据意愿的内容选择适当的组件来响应。
3. Intent不仅可用于应用程序之间,也可用于应用程序内部的activity, service和broadcast receiver之间的交互
4. Intenet大致可以分为两种,显示Intent和隐式Intent
二、Intent的简单使用
1.Activity
Intent intent = new Intent( FirstActivity.this , SecondActivity. class );
<pre name="code" class="html"><span style="white-space:pre"> </span><span style="font-size:24px;">startActivity(intent);</span>
2. Service
启动服务
<span style="font-size:24px;"><span style="white-space:pre"> </span> Intent intent = new Intent(Activity.this, MyService.class);
startService(intent);</span>
停止服务
<span style="font-size:24px;"><span style="white-space:pre"> </span>Intent intent = new Intent(Activity.this, MyService.class);
stopService(intent);</span>
3. 广播
<span style="font-size:24px;">Intent intent = new Intent("com.example.broadcasttest.MY_BROADCAST");</span>
<span style="font-size:24px;">//自定义广播,AndroidManifest文件中符合此调节的广播接收器,接收此条广播</span>
<span style="font-size:24px;">sendBroadcast(intent);</span>