4

我从一个单独的类中获得了这个方法,其中当调用结束时,我的 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 的东西。我只是想摆脱它,但我不确定除此之外的任何其他选择。帮助。谢谢。

4

1 回答 1

5

Use Handler instead of putting thread to sleep.

So instead of your if(true) {.....} try this:

Handler h = new Handler();
h.postDelayed(new Runnable() {
    @Override public void run() {
        //new intent here
    }
}, 10000);
于 2015-04-15T15:37:40.290 回答