我从一个单独的类中获得了这个方法,其中当调用结束时,我的 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
}
当进入我放置 Thread.sleep 的“if”条件时,问题就开始了。在执行下面的代码之前等待 10 秒
TargetDetails.oncall.setVisibility(View.VISIBLE);
TargetDetails.endcall.setVisibility(View.GONE);
我想我在这里遗漏了一些关于 Thread.sleep 的东西。我只想摆脱它,但我不确定除此之外还有其他选择。帮助。谢谢。
最佳答案
使用Handler而不是让线程 hibernate 。
所以代替你的 if(true) {.....}
试试这个:
Handler h = new Handler();
h.postDelayed(new Runnable() {
@Override public void run() {
//new intent here
}
}, 10000);
关于Java runOnUiThread 和 Thread.sleep,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29654421/