Skip to content
Daniel Bergløv edited this page Oct 25, 2015 · 1 revision

Back to Home


The ThreadHandler class is basically a Handler only it handles all of it's work from within it's own Thread. Google made a special HandlerThread class, which is an extended Thread class that could be used along with a regular Handler to obtain this feature. But instead of creating a HandlerThread instance only to parse it's Looper to the Handler, it seams better and easier to simply create a new Handler that does all of this automatically.

Example

Handler mHandler = new ThreadHandler("Thread Name", Process.THREAD_PRIORITY_BACKGROUND) {
    @Override
    public void handleMessage(Message msg) {
        // This message is handled in a background Thread
    }
};