实时数据与处理程序和本地广播
我有旧的Android / java代码,其中包含两个派生自,并且这些服务不在单独的进程中运行。IntentService
问题是关于从这些返回结果的方法。IntentService
一个服务通过使用 + 返回结果,以在主循环中运行代码:Handler
Runnable
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
MyApplication.get().setFoo(someThing);
}
});
另一个是用于将消息发送到 ,并通过 中的消息订阅,并在 中取消订阅。LocalBroadcastManager.getInstance(this).sendBroadcast(in);
Activity
Activity
BroadcastReceiver
onResume
onPause
我说得对吗,在这两种情况下,都可以用它来简化事情?LiveData
IntentService
应该创建和谁想要结果应该它,当新数据到达时应该调用,或者可能有一些珊瑚礁来阻止使用这里?LiveData
observe
IntentService
postValue
LiveData