Skip to content

Repository files navigation

HandlerLearing

This is a project generated by AS, so there are two dir in the project:

App and handlerdemo where App is empty that can be ignore;


Introduction

If you wonder why looper does not interrupt the app, this demo may enlight youIt is just a demo to show how the handler can update ui when get a message from another thread;


Directories

image

Flow

image

MultiThreadDemo is the entry

Two comparision to show the key of the Handler;

###One comparision:

In another thread, handler's multiThreadTest is invoked. The result is obvious;

public static void compareInAnotherThread(final Handler handler){
new Thread(new Runnable(){
@Override
public void run() {
handler.multiThreadTest();
System.out.println("compareInAnotherThread:"+Thread.currentThread().getName());
}
}).start();
}

###The other comparision:

A while without interruption is used to get the message from messagequeue; It is what we called looper;

public static void compareWithLooperThread(final Handler handler){
final MessageQueue q = new MessageQueue();
new Thread(new Runnable(){
@Override
public void run() {
q.enqueueMessage(new Message(0));
System.out.println("compareLooperThread:"+Thread.currentThread().getName());
}
}).start();
while (true){
handler.sendMessage(q.next());
}
}

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages