Skip to content

joyruby/HandlerLearing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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 you It 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

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages