gpt4 book ai didi

java - 我的代码中有一个第三方异步 block 。我怎么知道它什么时候结束?

转载 作者:行者123 更新时间:2023-11-29 19:20:23 25 4
gpt4 key购买 nike

我正在使用 Retrofit。 call.enqueue 异步执行。我有一段代码只有在 call.enqueue 成功执行后才能执行。

call.enqueue(new Callback<Event>() {
@Override
public void onResponse(Call<Event> call, Response<Event> response) {
returnedEvent = response.body();

}

@Override
public void onFailure(Call<Event> call, Throwable t) {
Toast.makeText(ViewEventActivity.this, "There was some internal error. Please try again!", Toast.LENGTH_SHORT).show();
}
});
//code block to be executed after the thread has been executed.
mTitle = (TextView) findViewById(R.id.event_title);
mStartTime = (TextView) findViewById(R.id.startsAt);
mEndTime = (TextView) findViewById(R.id.endsAt);
mEventTitle.setText(event.getTitle());

提前致谢!

最佳答案

onResponse 或 onFailure 被执行时意味着 call.enqueue 已经成功执行。你应该在这里添加你的 block 。

call.enqueue(new Callback<Event>() {
@Override
public void onResponse(Call<Event> call, Response<Event> response) {
returnedEvent = response.body();
//code block to be executed after the thread has been executed.
mTitle = (TextView) findViewById(R.id.event_title);
mStartTime = (TextView) findViewById(R.id.startsAt);
mEndTime = (TextView) findViewById(R.id.endsAt);
mEventTitle.setText(event.getTitle());
}

@Override
public void onFailure(Call<Event> call, Throwable t) {
Toast.makeText(ViewEventActivity.this, "There was some internal error. Please try again!", Toast.LENGTH_SHORT).show();
}
});

关于java - 我的代码中有一个第三方异步 block 。我怎么知道它什么时候结束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42661288/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com