触发器:

Intent intent = new Intent();
intent.putExtra("names_music", list_names.get(positions));
intent.setAction("android.intent.action.names");
MyService.this.sendBroadcast(intent);

接收器:(单独的类中)

class myReceiver extends BroadcastReceiver(){

@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String str=intent.getStringExtra("names_music");
}

}

注册: MyReceiver最好和发送端在同一个包中

<receiver android:name=".MyReciver">
<intent-filter >
<action android:name="android.intent.action.names"/>
</intent-filter>
</receiver>

接收器(在Activity中)

private BroadcastReceiver receiver=null;

receiver= new BroadcastReceiver(){

@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String str=intent.getStringExtra("names_music");
player_names_textview.setText(str);
}

};

可以在onResume中注册接收器这样就不需要在manifest中配置了:

IntentFilter filter = new IntentFilter();
filter.addAction("android.intent.action.names");
this.registerReceiver(this.receiver, filter);

在activity退出时要取消注册

this.unregisterReceiver(this.receiver);

Boardcast03相关推荐

最新文章

  1. AI就是“大数据+机器学习”?答案是否定的
  2. 2008 R2 Server core 下的常用命令
  3. Django(part19)--Django中的应用
  4. postgresql两个列模糊比较_数据分析之SQL优化系列(二)---PostgreSQL 的索引
  5. MongoDB 数组类型查询 —— $elemMatch 操作符
  6. UnicodeDecodeError: 'gbk' codec can't decode byte 0xb1 in position 5: illegal multibyte sequence
  7. CF #319 div 2 D
  8. 【基础练习】【区间DP】codevs1090 加分二叉树题解
  9. 2016-05-06
  10. 视频剪辑入门技能快速分享
  11. 谈谈未来 APP 产品设计的革命性趋势
  12. 构筑企业供应链高效协同优势,智能供应链系统助推汽车服务行业数字化订单管理
  13. 如何利用工具低成本构建阿里云灾备方案?
  14. 使用Python和Numpy构建神经网络模型
  15. 什么是龙格现象(Runge phenomenon)?如何避免龙格现象?
  16. Versal ACAP AI 引擎入门
  17. 解决申请开发者office E5中无法发送手机验证码,reCaptcha加载失败
  18. 一语中的!抽象工厂和一般工厂的缺点
  19. 外贸跨境电商必备九款实用APP软件盘点,外贸人必看
  20. 【Python3】中str方法汇总

热门文章

  1. Nginx的双向认证
  2. lzx和网页之间脚本交互调试方式
  3. iOS-----GitHub上比较齐全的iOS 工具和App
  4. 大数据是什么意思?大数据有哪些应用?
  5. html模态框常见问题,模态框无法弹出的问题
  6. Android允许应用具有安装权限
  7. 个人独资企业,核定征收;怎么申请?
  8. 为火狐浏览器安装debug(小虫子)调试工具
  9. 高德打车通用可编排订单状态机引擎设计
  10. java倒序查询数据库_数据库 倒序查询