[英]Java runOnUiThread and Thread.sleep
我从一个单独的类中有这个方法,当调用结束时,我的ImageView的颜色从红色变为白色。 示例代码如下:
public void endOfCall(){
((Activity)mContext).runOnUiThread(new Runnable(){
@Override
public void run(){
TargetDetails.oncall.setVisibility(View.VISIBLE);
TargetDetails.endcall.setVisibility(View.GONE);
}
});
try{
call.endCall();
}catch (SipException se) {}
call.close();
//this is just a representation; not the actual code
if(true){
Thread.sleep(10000);
}
//new intent here
}
当它进入'if'条件时,问题就开始了,我将Thread.sleep置于其中。 在下面的代码执行之前等待10秒
TargetDetails.oncall.setVisibility(View.VISIBLE);
TargetDetails.endcall.setVisibility(View.GONE);
我想我在这里错过了关于Thread.sleep的一些东西。 我只是想摆脱它,但我不确定除此之外的任何其他选择。 救命。 谢谢。
使用Handler而不是让线程进入睡眠状态。
所以代替你的if(true) {.....}
试试这个:
Handler h = new Handler();
h.postDelayed(new Runnable() {
@Override public void run() {
//new intent here
}
}, 10000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.