解决办法:加上 postInvalidate()
方法。
@Override protected void onRestart() {
super.onRestart(); /onRestart中开启新线程,更新UI/
Thread thread = new Thread(new Runnable() {
@Override public void run() {
System.out.println(Thread.currentThread().getName() + ": " + Thread.currentThread().getId());
tv.postInvalidate(); btn.postInvalidate();
tv.setText(“update UI is success!”);
btn.setText(“update UI is success!”);
}
});
thread.start();
}
postInvalidate()
方法,源码:
public void postInvalidate() {
postInvalidateDelayed(0);
}
public void postInvalidateDelayed(long delayMilliseconds) {
// We try only with the AttachInfo because there’s no point in invalidating
// if we are not attached to our window
if (mAttachInfo != null) {