Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
好的,我被卡住了。有人可以指出我正确的方向吗?我不知道从哪里开始挂起意图。我需要启动自定义服务,将一些数据发送回启动它的活动。我该怎么做?
如果您希望 Activity 在服务运行时始终处于活动状态(可见),则应考虑使用 AsyncTask。
我可能会在我的活动中注册一个广播接收器,如果我需要从服务到活动进行通信,请从服务发送一个广播,只要活动当前正在运行,活动的接收器就会接收它。顺便说一句,这不需要使用 PendingIntent。PendingIntents 更多地用于来自 AlarmManager 的警报或通知。