zoukankan      html  css  js  c++  java
  • 【转】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

    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);
  • 相关阅读:
    React创建组件的方式
    react jsx语法
    mui区域滚动失效的问题
    css3 currentColor
    http协议
    iframe用法
    html关于强制显示、隐藏浏览器的滚动条
    null与undefind的区别(转)
    如何实现背景透明,文字不透明,兼容所有浏览器?
    事件委托
  • 原文地址:https://www.cnblogs.com/wi100sh/p/4419900.html
Copyright © 2011-2022 走看看