【转】Usage of sendBroadcast()

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

时间: 2024-10-29 10:45:37

【转】Usage of sendBroadcast()的相关文章

sharepoint 2013 开启 Usage and Health Data Collection

Usage and Health Data Collection Monitoring the status of your farm's health is a critical aspect of SharePoint administration. This service application collects the various logging information stored in SharePoint and writes it to the logging databa

[转]Disk Space Usage and SQL Server Performance

Disk Space Usage and SQL Server Performance By Gregory A. Larsen When you think of SQL Server performance components, you think of the usage of CPU, memory, and the I/O it takes to process a query. However, there is another component you should consi

CSS减肥的工具–Firefox插件 CSS Usage

首先,我们需要安装Firefox(猛击此处下载),或者确定你已经安装的版本已经高于3.1; 第二步,安装前端开发人员最普及的开发工具 Firebug: 第三步,安装CSS Usage 0.3.4.1: 第四步,在浏览器中打开我们要优化的页面(本地的页面也可以),点击右下角的firebug小图标,打开firebug工具窗口,我们会看到在工具选项中我们有一个 CSS Usage工具的按钮. 首先我们来分析最上面的三个功能按钮的使用 Scan: 通过字面意思我们就能知道,这是一个扫描当前页面的工具,如

【DataStructure】Description and usage of queue

[Description] A queue is a collection that implements the first-in-first-out protocal. This means that the only accessiable object in the collection in the first one that was inserted. The most common example of a queue is a waiting line. [Interface]

【DataStructure】One of queue usage: Simulation System

Statements: This blog was written by me, but most of content  is quoted from book[Data Structure with Java Hubbard] [Description] This simulationillustrates objectoriented programming(OOP). Java objects are instantiated to represent all the interacti

[转]printk usage

原文地址:http://elinux.org/Debugging_by_printing#Usage If variable is of Type, use printk format specifier: --------------------------------------------------------- int %d or %x unsigned int %u or %x long %ld or %lx unsigned long %lu or %lx long long %l

Windows 8 Disk Usage Keep up 100%

Recently i find the windows8 Disk Usage always keep up 100%, It must be have some issue. Step1. Go into Open Task Manager Step2. Go to Details tab Step3. Right click the columns headers and click "Select Columns" Step4. From the "Select Col

Linux tar command usage

Linux tar command usage */--> Linux tar command usage Table of Contents 1. Create an archive: 2. Create a gzipped archive: 3. List the files in an archive 4. Add a file or directory to an existing archive The frequently used tar command are listed as

A Complete Guide to Usage of ‘usermod’ command– 15 Practical Examples with Screenshots

https://www.tecmint.com/usermod-command-examples/ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- In Unix/Linux distribut