Android
[Android] java.lang.IllegalStateException: Already executed
너츠너츠
2022. 7. 18. 19:58
배경
retrofit을 이용하여 작업할 때 화면을 회전시키면 Already executed 에러가 발생하였습니다
해결방법
Java과 kotlin 해결방법 모두 같습니다
storeInfoCall.enqueue(new Callback<StoreInfo>() {
@Override
public void onResponse(Call<StoreInfo> call, Response<StoreInfo> response) {
itemLiveData.postValue(response.body().getStores());
}
@Override
public void onFailure(Call<StoreInfo> call, Throwable t) {
Log.e(TAG, "onFailure: ", t);
itemLiveData.postValue(Collections.emptyList());
}
});
call과 enqueue 사이에 clone()를 붙여주시면 해결됩니다.
storeInfoCall.clone().enqueue(new Callback<StoreInfo>() {
@Override
public void onResponse(Call<StoreInfo> call, Response<StoreInfo> response) {
itemLiveData.postValue(response.body().getStores());
}
@Override
public void onFailure(Call<StoreInfo> call, Throwable t) {
Log.e(TAG, "onFailure: ", t);
itemLiveData.postValue(Collections.emptyList());
}
});
<참고>
Retrofit "IllegalStateException: Already executed"
I have a Retrofit network call that id like to run every 5 seconds. My current code: Handler h = new Handler(); int delay = 5000; //milliseconds h.postDelayed(new Runnable() { public void run...
stackoverflow.com
반응형