Android: Detect UI change and stop threads
<p>I have an App that has a thread handler  receiving some socket data all the time.
I want this thread to be closed along with the termination of socket whenever the Apps is not on foreground. I'm assuming this can be done on Android without issues.</p>

<p>How can this be done?
I would also like the socket to be reopened and the reception of data to begin once the UI comes to the foreground(or the Apps comes to foreground). At the moment, my socket opening calls are all done in such a way that during "onCreate" the thread handler is started which takes care of socket and getting data from it.</p>
