首先,我启动ActivityB
并单击getUdpMsg
按钮。将Handler
收到消息并刷新 UI。
然后,我回到ActivityA
,再次启动ActivityB
,并单击相同的按钮。但是,UI 不会刷新。
但是 UI setText 从日志中成功。
为什么?
public Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what == 1) {
receiveMsg = udpSocketReceive.receiveMsg;
Log.d("test", "receive = " + receiveMsg);
// 解析接收到的消息
messageReceive = new MessageReceiveUDP(receiveMsg);
messageReceive.parseUDPRecvMsg();
if (!messageReceive.isValid()) {
Log.e("Error", "The received msg is invalid");
} else {
Log.d("testt", "valid msg");
// 解析的结果显示在UI上
udpreceiveflag = true;
// udpSocketReceive.setLife(false);
setResultOnUI(messageReceive);
(new View(context)).invalidate();
Log.d("debug","after invalidate ip = " +chabanipTextView.getText().toString());
}
}
}
};