-1

I have started a thread which connected to bluetooth device and streams data. I actually started this thread from a service(Thread not started from activity). So know I need to communicate to activity to show the list of input streams. I am not sure if event bus can provide a such a high frequently changing data. Can some one give me a better existing examples of how to use display the streams.

Please don't ask me for the source code.

2 Answers2

0

I believe Event bus can be a good solution, also check bound services: https://developer.android.com/guide/components/bound-services.html

Mina Wissa
  • 10,923
  • 13
  • 90
  • 158
0

I advise you to look into LiveData from the Android architecture components. You can observe the result from the activity, and it will "unsubscribe" for you when needed (onStop()). You can read about the advantages on the link I provided.

You could extend a LiveData and implement the logic inside it (like this example), or just use it to dispatch the updates, then observe it on the Activity. The postValue() method will ensure that it gets dispatched on the MainThread.

mVck
  • 2,910
  • 2
  • 18
  • 20
  • Hey I tried to use Live data but the initialization of live data from service or background thread but i was not able to work on it. Can you explain more about using Live data from a thread started by a service. – Avinash Reddy Chintareddy Feb 20 '18 at 18:35