I've been looking at the HandlerThread class as originally I was using a simple thread and handler, but came a cropper with the NetworkOnMainThreadException in android.
I can't seem to understand how I would be able to introduce things like sockets into a HandlerThread, something where you'd put the blocking code in run. But you cannot do that with a HandlerThread since you shouldn't override run as that is where the looper is.
And I cannot call the HandlerThread via messages to start listening on sockets as it would then block any other messages passed to it.
So is this HandlerThread class designed for tasks which are non blocking? As I cannot seem to understand how I can use such a thread so it can listen on a socket but can deal with requests Like when I was creating a normal thread from the main UI thread
I could, in a normal thread, call Looper.prepare() and Looper.loop() in run, then put the code between these two lines(With a check to create the handler) but then I've got problems of communicating with this new thread, messages aren't passed into the thread.
So how do I go about creating threads which can use handlers to communicate with each other and are doing tasks such as using sockets.
Please I'm not looking for use ASyncTask comments, I want to know how I can use threads myself, so threads can communicate with each other