原文网址: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

2 Answers

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. intellij IDEA 出现“Usage of API documented as @since 1.6+”的解决办法

    问题 在导入java.io.console的时候出现"Usage of API documented as @since 1.6+"

  2. Disk Space Usage 术语理解:unallocated, unused and reserved

    通过standard reports查看Disk Usage,选中Database,右击,选择Reports->Standard Reports->Disk Space Usage,截图如 ...

  3. OpenCascade MeshVS Usage

    OpenCascade MeshVS Usage eryar@163.com Abstract. MeshVS means Mesh Visualization Service. It can be ...

  4. Usage: AddDimensionedImage imageFile outputFile eclipse 运行程序出错

    关于这个在eclipse中运行java程序的错,首先确认你的jdk,jre是否完整,并且与你的eclipse的位数相同,当然我相信这个错误大家应该都会去检查到. 第二个关于addDimensioned ...

  5. Please allow Subclipse team to receive anonymous usage statistics for this Eclipse intance(info)

    本文转载自:http://blog.csdn.net/myfxx/article/details/21096949 今天在用eclipse启动项目的时候发现了一个问题,就是每次启动项目的时候,ecli ...

  6. [转]Dynamic SQL & Stored Procedure Usage in T-SQL

    转自:http://www.sqlusa.com/bestpractices/training/scripts/dynamicsql/ Dynamic SQL & Stored Procedu ...

  7. 处理Linux下subversion尝试连接自建的VisualSVN server报“Key usage violation in certificate has been detected”错误的问题

    在Linux下使用subversion尝试链接VisualSVN server搭建的svn库,可能会报下面错误, svn: OPTIONS of 'https://server.domain.loca ...

  8. 应用alter index ××× monitoring usage;语句监控索引使用与否

    随着时间的累积,在没有很好的规划的情况下,数据库中也许会存在大量长期不被使用的索引,如果快速的定位这些索引以便清理便摆在案头.我们可以使用"alter index ××× monitorin ...

  9. hadoop 2.5 hdfs namenode –format 出错Usage: java NameNode [-backup] |

    在 cd  /home/hadoop/hadoop-2.5.2/bin 下 执行的./hdfs namenode -format 报错[hadoop@node1 bin]$ ./hdfs nameno ...

随机推荐

  1. DataTbale取值

    有一个DataTable数据 //创建DataTable对象 DataTable dt = new DataTable("Table_AX"); //为DataTable创建列 / ...

  2. 国际化 native2ascii用法

    cmd下输入: native2ascii -encoding GBK(需要编译成哪种语言) (中文文件路劲) (英文文件路劲) 其他固定 例如 native2ascii -encoding GBK C ...

  3. 判断PHP数组是否为空的代码

    PHP判断数组为空首选方法:count($arr),size($arr); 复制代码 代码如下: $arr= array(""); echo count($arr); echo s ...

  4. 如何制作css3的3d动画——以骰子旋转为例,详解css3动画属性

    首先先来看两个用css3实现的炫酷的3d动画效果 1 2 3 4 5   6 你没看错,这个炫酷的效果都是用css3实现的. 下面是动画实现所需要用到的几个css3属性. 1.perspective: ...

  5. Java GC 日志输出分析

    搜到的几篇讲GC日志的文章,学到了很多东西.但是有些错误或者不够精确的地方. 因此自己尝试着总结一下. 先写个程序,然后结合程序解释每句话的意思. 运行参数 -Xms200M -Xmx200M -Xm ...

  6. 英语学习[ZZ]

    本文作者三年间从四级勉强及格到高级口译笔试210,口试232.找工作面试时给其口试的老外考官听了一分钟就说你的英语不用考了.虽不敢说方法一定是最好的,但从现在开始随便谁不要再去找学习资料,每天花两个钟 ...

  7. opencv 常用函数介绍

    ××××××××××××××××××××××××××××××××××××××× CvScalar imgmean,imgstd; double imgmax,imgmin; cvAvgSdv(img, ...

  8. jQuery慢慢啃之CSS(六)

    1.css(name|pro|[,val|fn])//访问匹配元素的样式属性 $("p").css("color");//获取 $("p") ...

  9. Linux之Vim编辑器使用

    vim文本编辑器用于建立 编辑 显示文本文件,vim没有菜单,只有命令 在windows 平台下可使用gvim进行编写 Vim三种工作模式: 常有命令: 1.INSERT插入命令 i 在光标前插入 I ...

  10. 用urlencode(String str)对URL传递参数进行编码,提高安全

    在PHP 提交地址后面带有参数的时候,参数会在浏览器的地址栏暴露无疑,这样是不安全的,这个时候就必须用些方法对这些参数进行安全处理 这里可以用 urlencode(String URL);//对URL ...