Android 2.1: Muliple Handlers in a Single Activity

Posted by Soumya Simanta on Stack Overflow See other posts from Stack Overflow or by Soumya Simanta
Published on 2010-05-13T19:15:04Z Indexed on 2010/05/13 19:44 UTC
Read the original article Hit count: 270

Filed under:
|
|
|

Hi,

I've more than one Handlers in an Activity. I create all the handlers in the onCreate() of the main activity. My understanding is the handlerMessage() method of each handler will never be called at the same time because all messages are put in the same queue (the Activity thread MessageQueue). Therefore, they will be executed in the order in which are put into the Queue. They will also be executed in the main activity thread. Is this correct ?

 public void onCreate() {

this.handler1 = new Handler() {
@Override
public void handleMessage(Message msg) {

                            //operation 1 : some operation with instanceVariable1
super.handleMessage(msg);
}
};

this.handler2 = new Handler() {

@Override
public void handleMessage(Message msg) {
                            //Operation 2: some operation with instanceVariable1
super.handleMessage(msg);
}

};

this.handler3 = new Handler() {
@Override
public void handleMessage(Message msg) {
                            //Operation 3: some operation with instanceVariable1
super.handleMessage(msg);

}
};
}

© Stack Overflow or respective owner

Related posts about android

Related posts about handler