Intent学习(1)

<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>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值