原文网址:http://stackoverflow.com/questions/4883079/usage-of-sendbroadcast

sendBroadcast() - Should it be called inside Activity? I am trying to call sendBroadcast() from my method of utility-class which doesn't extend Activity. I am getting compilation error as below

The method sendBroadcast(Intent) is undefined for the type MyWrapperClass MyWrapperClass.java

Here is the code snippet:

abstract class MyWrapperClass {public static void sendData(){Intent intent = new Intent ("com.proj.utility.mgr",null);intent.putExtra("example","Broadcasting "); sendBroadcast(intent);}}

Is there any concept behind using sendBroadcast call inside my class. There is no issue in using sendBroadcast() inside Activity. Can someone here help me to resolve it? Or Any other suggestions are invited to return data from utility class to application asynchronously. Thanks in advance.

 
2  
you need access to the application context to call sendbroadcast. Could you not get this information from android documentnation. –  doc_180 Feb 3 '11 at 6:55
add a comment

2 Answers

activeoldestvotes

up vote15down vote

You should pass the context from activity class to utility class to access the specific application resources like startActivity, sendBroadcast, etc.

context.sendBroadcast(intent);

【转】Usage of sendBroadcast()相关推荐

  1. CUDA Samples: Streams' usage

    以下CUDA sample是分别用C++和CUDA实现的流的使用code,并对其中使用到的CUDA函数进行了解说,code参考了<GPU高性能编程CUDA实战>一书的第十章,各个文件内容如 ...

  2. Redis报错解决The TCP backlog setting of 511 cannot be enforced和This will create latency and memory usage

    在启动Redis的时候报错如下: 16426:M 04 May 10:30:43.721 # WARNING: The TCP backlog setting of 511 cannot be enf ...

  3. -mkdir 创建目录 Usage:hdfs dfs -mkdir [-p] < paths> 选项:-p 很像Unix mkdir -p,沿路径创建父目录。

    1 -mkdir 创建目录 Usage:hdfs dfs -mkdir [-p] < paths> 选项:-p 很像Unix mkdir -p,沿路径创建父目录. 1,-mkdir 创建目 ...

  4. SAP WM中阶Storage Type的Capacity Check – Usage check based on material

    SAP WM中阶Storage Type的Capacity Check – Usage check based on material 1, Storage type Z03激活了Capacity C ...

  5. SAP QM QS41 试图维护Catalog为3的Code Group, 报错-You need to maintain catalog 3 (Usage Decisions) in Customi

    SAP QM QS41 试图维护Catalog为3的Code Group, 报错-You need to maintain catalog 3 (Usage Decisions) in Customi ...

  6. [C++] NEW Advanced Usage

    NEW Advanced Usage 将分配的内存限定在特定的一块区域 #include<iostream> #include<new> const int buf(512); ...

  7. mysql中usage是什么权限?

    2019独角兽企业重金招聘Python工程师标准>>> mysql中usage是什么权限? 50 如题,我在phpmyadmin中发现自己新建的用户的权限是usage,这是什么权限啊 ...

  8. perl的Getopt::Long和pod::usage

    代码: 需要显式地定义变量且初始化.例如optionX. 如果没有定义变量且显式初始化,且没有在命令行指定选项,则选项对应的变量将为未定义. #!/bin/perl-5.8.3/bin/perl$ u ...

  9. shell usage file

    2019独角兽企业重金招聘Python工程师标准>>> #!/bin/ksh #=================================================== ...

最新文章

  1. Swift 中的 @autoclosure
  2. ubuntu 常见问题系列:E:Could not get lock /var/lib/dpkg/lock-frontend - open
  3. postman显示服务器错误是什么原因,Postman 500内部服务器错误api错误
  4. Python---堆里有16颗豆子,有两个玩家依次取豆
  5. mac如何清空Recent Places
  6. Linux中mount挂载命令及其概念
  7. 【题解】LuoGu4158:粉刷匠
  8. 摩尔庄园服务器显示不出,摩尔庄园电脑为什么玩不了 摩尔庄园电脑玩不了解决方案...
  9. 2021.11.16【读书笔记】丨宏基因组分析流程
  10. 从小程序快速扫码进微信群聊
  11. Leetcode-1737-满足三条件之一需改变的最少字符数
  12. 【Android】应用偏好设置
  13. xp计算机远程桌面设置密码,远程桌面连接设置,详细教您xp怎么设置远程桌面连接...
  14. 伦敦银开盘时间知多少
  15. 小程序实现关注公众号的代码
  16. 软银与ARM联合公开信:ARM已成软银集团一员 业务如常
  17. NVML查询显卡信息
  18. 使用vue实现手写签名功能
  19. 富文本解析 wxParse 解析数据造成页面假死
  20. 火狐强制刷新_强制Firefox 3在Windows XP中使用Vista默认主题

热门文章

  1. c3p0对mysql配置_c3p0的常用配置方式
  2. java oracle行锁,Oracle 出现行锁 错误代码 ora-02049
  3. python pptx 从中间加几页_python-pptx---插入表格
  4. jmeter 导入java_8. Jmeter导入jar包
  5. 利用MEGA32制作辉光数码管显示电路
  6. 骑摩托的蒙娜丽莎 - 曼妙风骚的花式慢跑算法
  7. 智能车竞赛秘书处与RT-Thread关于第十七届智能车竞赛第一次会议
  8. 十六届全国大学生智能车竞赛线上比赛的队伍看过来,你们需要的图片都在这儿
  9. 2021年春季学期-信号与系统-第三次作业参考答案-第四道题
  10. 无线节能信标调试说明-2021-3-3