Android Handler的几种写法

直接在oncreate()中创建

    public void onCreate(Bundle savedInstanceState){
super.onCreate(this, savedInstanceState);
setContentView(R.layout.chatroom);
mContext = this;
mInstance = this;

init();
PhoneManager.getInstance().setOnTextReceivedListener(new PhoneOnTextReceivedListener(){

@Override
public void onTextReceived(LinphoneAddress from, String message) {
remoteInfo = from.asString();
remoteInfoUl = from.asStringUriOnly();
remoteMessage = message;
mHandler.post(new Runnable() {
@Override
public void run() {
text_showmessage.setText(remoteMessage);

}
});
}
在activity中创建,然后再需要使用的时候讲对应的函数嵌套进去

private Handler mHandler = new Handler(){
@Override
public void handleMessage(Message msg){
if(msg.what==1){
text_showmessage.setText(remoteMessage);
}

}
};


PhoneManager.getInstance().setOnTextReceivedListener(new PhoneOnTextReceivedListener(){


@Override
public void onTextReceived(LinphoneAddress from, String message) {
remoteInfo = from.asString();
remoteInfoUl = from.asStringUriOnly();
remoteMessage = remoteInfoUl+":\n"+message;

mHandler.sendMessage(Message.obtain(mHandler, 1));

}


你可能感兴趣的:(Android Handler的几种写法)