Hello,

I'm using HandlerThread like below in my app. Is it correct ?


public class MyThread extends HandlerThread implements Callback
{
    public ThreadDP(Handler uiHandler)
    {
        super(MyThread.class.getSimpleName(), Process.
THREAD_PRIORITY_DISPLAY);
        mUiHandler = uiHandler;
        this.start();
    }


    @Override
    protected void onLooperPrepared()
    {
        super.onLooperPrepared();
        synchronized (this) {
            mThreadHandler = new Handler(getLooper(),this);
            notifyAll();
        }
    }


    public LabelList getLabels()
    {
        //Get some datas from network
        return labels;
    }


    @Override
    public boolean handleMessage(Message msg) {


        Message message;
        Bundle bundle;


        switch (msg.what)
        {
            case ThreadMessages.GET_LABELS : 


            message = mUiHandler.obtainMessage();
            message.what = ThreadMessages.GET_LABELS;


            Bundle bu = new Bundle();
            bu.putInt("myapp.idThread", mIdThread);
            bu.putParcelable("myapp.label", this.getLabels());
            message.setData(bu);
            this.uiHandler.sendMessage(message);
            return true;
        }
    }
}


And then : 

mThread = new MyThread(uiHandler);
mThread.start();
mThread.getHandler().sendEmptyMessage(ThreadMessages.GET_LABELS);

The communication between the thread and UI is going pretty well , but i'm 
little confused by the lack of runnable. Should is keep using this way or 
am i missing something important ? 

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/6d8a26a3-107c-44a3-a430-93b4a165ae69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to