【问题标题】:How get Activity form BroadcastReceiver in onReceive如何在 onReceive 中获取 Activity 表单 BroadcastReceiver
【发布时间】:2013-07-16 05:36:51
【问题描述】:

我在应用程序清单中定义了 BroadcastReceiver,并且接收器按预期在 onReceive 中接收事件。但是,我没有创建接收器类,因此我无法传递有关接收器应该控制的活动的任何信息。上下文参数只给我应用程序上下文,没有任何活动参考。那么在应用程序活动和广播接收器之间进行通信的正确方法是什么?

【问题讨论】:

标签: android broadcastreceiver


【解决方案1】:

答案有点扭曲,但我也在这里找到了 Inform Activity from a BroadcastReceiver ONLY if it is in the foreground 它似乎工作。那么请关闭问题。

【讨论】:

    【解决方案2】:

    您可以通过以下方式将广播传达给活动:-

       Intent intent=new Intent(context,YourActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
               context.startActivity(i);
    

    【讨论】:

    • 我不需要开始活动,我需要与现有活动进行交流。
    猜你喜欢
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多