广播接收器只能在没有开始新活动的情况下才能将信息发送到活动?
我有一个广播接收器,该接收器会在地理上事件上触发,并且使用服务器“时钟”或“时钟”。如果我的应用程序的“出勤”活动已经打开仅开放。
我想象的方式是在广播接收器上向活动发送意图,但是命名“ startactivity()”听起来并不令人鼓舞,除非我可以通过任何特殊的旗帜来防止启动尚未开放的活动 - 我似乎找不到任何。
另一个选择是在活动开放时不断对价值进行投票,但似乎并不最佳有意图。
I have a broadcast receiver that gets triggered on geofencing events and either "clocks in" or "clocks out" with the server. If my application's "Attendance" activity is already open I would like it to display the clocking status change but I don't want the Broadcast Receiver to start the activity if it's not open - in other words display the change "live" while the activity is open only.
The way I imagine doing this is with the Broadcast Receiver sending an Intent to the activity but name "startActivity()" doesn't sound encouraging unless there are any special flags I can pass to prevent starting an Activity that isn't already open - I can't seem to find any.
The other option would be to constantly poll the value while the activity is open but it doesn't seem optimal so I would only use it if there wasn't another way and I can't think of a reason why it couldn't be possible with Intents.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有几种不同的方法可以完成相同的任务。一个人像以下示例一样注册听众:
MainActivity
接收器
There are several different ways to accomplish the same task. One is registering a listener like the following example:
MainActivity
Receiver
只需让您的
broadcastreceiver
发送广播意图
即可。您的活动
应从此广播意图
中注册一个侦听器,如果它触发了,则可以更新UI。这是一个示例:
在您的
活动
中声明私有成员变量:在
activity.oncreate()
中,注册broadcastreceiver
:in
in
OnDestroy()
您可以取消注册(可能不是必需的,但更清洁):在您的
broadcastreceiver
中检测到地理范围事件的,您应该创建并发送广播::Just have your
BroadcastReceiver
send a broadcastIntent
. YourActivity
should register a listener from this broadcastIntent
and if it gets triggered, it can update the UI.Here's an example:
Declare a private member variable in your
Activity
:In
Activity.onCreate()
, register theBroadcastReceiver
:And in
onDestroy()
you can unregister it (probably not necessary, but cleaner):In your
BroadcastReceiver
that detects the geofencing event, you should create and send a broadcastIntent
: