Android Question

Android: one handler for all runnables?

Can I use one handler in my Activity for all runnables or should I have multiple instances of Handler, each for one runnable?

Answer Source

You can use only one handler and to specify from where your are coming use different message.

handler.sendEmptyMessage(messagevalue);  //use this to send message from different place

Now handle message

    private Handler handler=new Handler(){

    public void handleMessage(Message msg) {
        //specify msg value
            //do this
        }else if(msg.what==20){
            // do this
            //so on....
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download