Manage API calls with Java [Android] -
i trying manage request calls. here situation. using retrofit 2 rxjava. have api request call in onresume method in fragment. when switch tabs in application or rotate phone onresume method gets called again , if call slow send 2 same requests , 2 identical responses. have idea how can prevent this?
i not send second api call if first 1 ongoing or somehow merge 2 responses 1 if calls same.
thanks
you can create flag wrapping api , make false while requesting , true on response
private boolean canrequest = true; void onresume(){ if(canrequest){ canrequest = false; fetchdatausingretrofit(new responsecallback(){ void onresponse(){ canrequest = true; } }); } }
Comments
Post a Comment