I learned about Looper and Handler, and in most cases I read about it, which it uses to communicate with the user interface thread. But then I saw code that was a child of the Handler class with the handleMessage(msg : Message) method, then I got confused because we can interact with the GUI thread without extending the Handler class. As an example in kotlin android.
val handler = Handler(); handler.post({ // update GUI here });
Therefore, I can easily interact with the GUI thread without implementing a child class or handleMessage() .
Let me explain a little more about my quesiton. Sometimes I see this example.
class HandlerSub : Handler(){ override fun handleMessage(msg : Message){ // update GUI here. } } val handler = HandlerSub(); handler.send({ // send something.. });
So, in the above example, both codes are used to update / interact with the GUI thread. but the first code is simpler and lighter code for interacting with the graphical interface.
Then what is the real purpose of the handleMessage() method and when should we implement it?
android kotlin
UnKnown Nov 16 '17 at 18:03 2017-11-16 18:03
source share