java - LiveData vs Handler and LocalBroadcast -


i have old android/java code, contains 2 derives intentservice, , these services not run in separate processes.

the question way return result these intentservice.

one service return result using handler + runnable, run code in main loop:

new handler(looper.getmainlooper()).post(new runnable() {     @override     public void run() {         myapplication.get().setfoo(something);     } }); 

the other 1 uses localbroadcastmanager.getinstance(this).sendbroadcast(in); send message activity, , activity subscribe via broadcastreceiver on message in onresume, , unsubscribe in onpause.

am right, , in both case possible use livedata simplify things?

intentservice should create livedata , want result should observe it, , when new data arrives intentservice should call postvalue, or may there reefs prevent usage of livedata here?

both methods work using livedata since purpose of livedata have on thread , still notify users when has changed. seems replace localbroadcastmanager.getinstance(this).sendbroadcast(in); , intentservice postvalue. have activity or needs aware of changes become observer.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -