Android PendingIntent 方法
好吧,我被困住了。有人可以指出我正确的方向吗?我不知道从哪里开始处理悬而未决的意图。我需要启动自定义服务,将一些数据发送回启动它的活动。我该怎么做呢?
Ok I am stuck. Can someone please point me in the right direction? I have no idea where to start with pendingintents. I need to start custom service that sends some data back to the activity that started it. How would I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可能会在我的活动中注册一个广播接收器,如果我需要从服务到活动进行通信,请从服务发送广播,只要活动当前正在运行,活动的接收器就会接收它。顺便说一句,这不需要使用 PendingIntent。 PendingIntents 更多地与来自 AlarmManager 的警报或通知一起使用。
I would probably register a Broadcast Receiver in my Activity and if I needed to communicate from Service to Activity, send a broadcast from the Service and the Activity's receiver would pick it up as long as the Activity was currently running. This, by the way, would not require the use of a PendingIntent. PendingIntents are more used with alarms from the AlarmManager or with Notifications.
如果您希望 Activity 在服务运行时始终处于活动状态(可见),则应考虑使用 AsyncTask。
You should consider using AsyncTask if you expect your Activity to be active (visible) all the time the Service runs.