【发布时间】:2020-06-22 09:23:48
【问题描述】:
我已经实现了一种向服务器发送数据的方法,但我想将实现的功能失败消息延迟大约 20 毫秒,
我的代码是
public void onFailure(Call call, IOException e) {
call.cancel();
Log.d("FAIL", e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
TextView responseText = findViewById(R.id.responseText);
responseText.setText("Failed to Connect to Server. Please Try Again.");
}
});
}
【问题讨论】:
-
它在 runOnUiThred 上不起作用
-
延迟 UI 线程是你不应该做的事情。将失败方法放在单独的线程中,如 ASyncTask 或使用 Handler 或类似的并在那里延迟。
-
@AHoneyBustard 但没有人在这里延迟 UI 线程,这里的情况更多是关于延迟一个动作并在一段时间后执行它而不是冻结 UI 线程:)
-
@Mariusz Brona 我知道,但这个问题可以很容易地解释为其他...
标签: android