博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Broadcast Receiver注意事项
阅读量:4330 次
发布时间:2019-06-06

本文共 716 字,大约阅读时间需要 2 分钟。

  • 静态登记
  • 动态注冊
@Overrideprotected void onStart() {    super.onStart();    IntentFilter intentFilter = new IntentFilter();    intentFilter.addAction("myAction");    registerReceiver(myReceiver, intentFilter);}@Overrideprotected void onPause() {    super.onPause();    unregisterReceiver(myReceiver);}
  • 发送广播
Intent intent = new Intent();intent.setAction("myAction");sendBroadcast(intent);

  • 注意事项:

假设没有加入IntentFilter的Action。那么BroadcastReceiver将的onReceive(Context context, Intent intent)将收不到通知。除非你在发送的时候指明的详细的Class:

Intent intent = new Intent(MyActivity.this,MyReceiver.class);sendBroadcast(intent);

版权声明:本文博主原创文章,博客,未经同意不得转载。

转载于:https://www.cnblogs.com/blfshiye/p/4888992.html

你可能感兴趣的文章
响应式web设计之CSS3 Media Queries
查看>>
实验三
查看>>
机器码和字节码
查看>>
环形菜单的实现
查看>>
【解决Chrome浏览器和IE浏览器上传附件兼容的问题 -- Chrome关闭flash后,uploadify插件不可用的解决办法】...
查看>>
34 帧动画
查看>>
二次剩余及欧拉准则
查看>>
Centos 7 Mysql 最大连接数超了问题解决
查看>>
thymeleaf 自定义标签
查看>>
关于WordCount的作业
查看>>
C6748和音频ADC连接时候的TDM以及I2S格式问题
查看>>
UIView的layoutSubviews,initWithFrame,initWithCoder方法
查看>>
STM32+IAP方案 实现网络升级应用固件
查看>>
用74HC165读8个按键状态
查看>>
jpg转bmp(使用libjpeg)
查看>>
linear-gradient常用实现效果
查看>>
sql语言的一大类 DML 数据的操纵语言
查看>>
VMware黑屏解决方法
查看>>
JS中各种跳转解析
查看>>
JAVA 基础 / 第八课:面向对象 / JAVA类的方法与实例方法
查看>>