本文介绍了sendBroadcast的使用()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

sendBroadcast() - 它是否应叫里面的活动?我想打电话给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

该方法sendBroadcast(意向)是  未定义的类型MyWrapperClass  MyWrapperClass.java

下面是code片断:

abstract class MyWrapperClass {

    public static void sendData()
         {
             Intent intent = new Intent ("com.proj.utility.mgr",null);

             intent.putExtra("example","Broadcasting "); 

            sendBroadcast(intent);

         }
    }

有没有用我的班级里sendBroadcast电话后面的任何概念。有一个在使用sendBroadcast()内的活动没有任何问题。有人可以在这里帮我解决这个问题?或任何其他建议,请从实用工具类数据返回给应用程序异步。先谢谢了。

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.

推荐答案

您应该通过从活动类中的上下文工具类访问特定应用程序的资源,如startActivity,sendBroadcast等。

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

context.sendBroadcast(intent);

这篇关于sendBroadcast的使用()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 08:46