Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 764
c0dehunter Avatar asked Feb 14 '12 09:02

c0dehunter


1 Answers

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(){

    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
        //specify msg value
        if(msg.what==10){
            //do this
        }else if(msg.what==20){
            // do this
        }else{
            //so on....
        }
    }  
   };
like image 153
Tofeeq Ahmad Avatar answered Nov 11 '22 13:11

Tofeeq Ahmad