【问题标题】:How to pass data from a service to activity using @Receiver?如何使用@Receiver 将数据从服务传递到活动?
【发布时间】:2016-09-04 10:22:53
【问题描述】:

我正在使用 Android 注释库,我想使用广播接收器将数据从服务传递到活动。我想利用@Reciever的Android注解,我的尝试和这个SO question一样

感谢任何帮助。

【问题讨论】:

    标签: android android-intent broadcastreceiver android-service android-annotations


    【解决方案1】:

    在您的Activity 中,添加此接收器方法:

    @Receiver(actions = "GPSLocationUpdates", local = true)
    void receiveLocationUpdates() {
     // TODO
    }
    

    并像往常一样从Service 广播您的Intent

    Intent intent = new Intent("GPSLocationUpdates");
    LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-29
      • 1970-01-01
      相关资源
      最近更新 更多