배경
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
반응형
'Android' 카테고리의 다른 글
[Android] 기본 구분선 추가하기 (0) | 2022.07.23 |
---|---|
[Android Kotlin] Google Login & registerForActivityResult (0) | 2022.07.20 |
[Android] RecyclerView 마지막 layout 잘림 현상 (0) | 2022.07.13 |
[Android] Gradlew Permission Denied (0) | 2022.07.11 |
[Android] Postman으로 FCM Push 알림 보내기 (0) | 2022.07.09 |
댓글