怎样使用PendingIntent让Service和Client进行交互

熟悉Android的朋友都知道使用bindService()启动Service可以通过IBinder对象实现Service和Client端通信,本篇文章并不是介绍启动Service的常见方法(startService()和bindService()),如果想知道Service的基本运用,请绕道……

本篇文章主要讲述一种并不是很常见的启动Service的方式,并与Service端进行交互的实现方式,准备好了吗?现在开始我们的探索之旅!

 俗话说,众里寻他千百度,蓦然回首那人却在灯火阑珊处。运用到学习知识上面也同样如此,为了探索PendingIntent启动Service的实现方式,搜索了很多资料都没有找到满意的结果。最终还是决定再撸一篇Android文档,终于皇天不负有心人,在文档中找到了相关的说明(Website:Android说明文档),因此建议大家多看Android说明文档,学会学习第一手知识的方法,也就是所说的多穿一手鞋。

以下是从文档中摘录的一段话(只要讲述了可以使用PendingIntent+Broadcast的方式实现Client和Service的交互):

If the service does not also provide binding, the intent delivered withstartService()is the only mode of communication between the application component and the service. However, if you want the service to send a result back, then the client that starts the service can create aPendingIntentfor a broadcast (withgetBroadcast()) and deliver it to the service in the Intentthat starts the service. The service can then use the broadcast to deliver a result.

 以上讲了那么多,现在来看看具体的实现方式吧!

 未完待续,敬请期待!

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值