I have old Android/java code, that contains two derives from IntentService
,
and these services not run in separate processes.
The question is about the way to return result from these IntentService
.
One service return result by using Handler
+ Runnable
, to run code in main loop:
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
MyApplication.get().setFoo(someThing);
}
});
the other one is uses LocalBroadcastManager.getInstance(this).sendBroadcast(in);
to send message to Activity
, and Activity
subscribe via BroadcastReceiver
on message in onResume
, and unsubscribe in onPause
.
Am I right, and in both case it is possible to use LiveData
to simplify things?
IntentService
should create LiveData
and who want result should observe
it,
and when new data arrives IntentService
should call postValue
,
or may be there are some reefs to prevent usage of LiveData
here?