Reputation: 10405
I'm developing an application which transmit information to network devices using a TCP connection. My main problem is I need to update UI every time a feedback or alert received from a devices. Since their feedback and response is unpredictable, I can not wait till they respond and user can move between different application Activities
. So when an alert or feedback receives, I should check which activity is on screen and update UI and pass messages between activities to let them what they should do and this is a complex task for many situation which may happen.
So I want to ask are there any know practices for this situation?
e.g. Is it good to run network communications as a service and pass intent to receivers on requires UI updates? Or is it good to run a handler for network communications...
Upvotes: 0
Views: 37
Reputation: 6067
I suggest you check EventBus. it will allow you to send events like local broadcast receiver. And from that you can listen specific event and display result.
Upvotes: 1
Reputation: 287
I would suggest to use receivers as you mentioned, and to detect in which activity the user is watching I would use the onResume and onPause methods in each activity to store the current one on the sqlite database.
Upvotes: 0