I am trying to find the right architecture to be able to listen to UDP Multicast socket, receive the datagram packet that is in JSON format and then send the data to my BroadCast Receiver. It is important that the UDP must always listen and store packets even when the application is minimized.
My current approach is to use a ThreadHandler and have the socket listen and interpret the packet within the method
run(). However, to keep the socket alive and keep listening i am passing
this reference as a
runnable within the
run method to keep it looping which I believe is a wrong practice.
So, what would be the “right” approach, in the context of using a Thread/ThreadHandler/Looper/Handler and what methods should be overridden?
Should I use a looper with
onLooperPrepared() doing the setup of socket etc and then do all the work in
run()? Maybe just use
handler to pass simple messages in the
MessageQueue and use
handleMessage() to interpret messages and send to
Thank your for your time.