Skip to content

Instantly share code, notes, and snippets.

@elihart
Last active August 29, 2015 14:16
Show Gist options
  • Save elihart/dd1815e2aa18656120fd to your computer and use it in GitHub Desktop.
Save elihart/dd1815e2aa18656120fd to your computer and use it in GitHub Desktop.
RequestManager
public class TestFragment extends AirFragment {
private static final int REQUEST_MANAGER_ID = 1;
@Inject RequestManager mRequestManager;
private RequestListener mListener = new RequestListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
@Override
public void onResponse(Object response) {
}
};
@Override
public void onPause() {
super.onPause();
mRequestManager.lockListeners(REQUEST_MANAGER_ID);
mRequestManager.removeListeners(REQUEST_MANAGER_ID);
}
@Override
public void onResume() {
super.onResume();
if (mRequestManager.hasRequest(REQUEST_MANAGER_ID, ListingAvailabilityRequest.class)) {
mRequestManager.setListener(REQUEST_MANAGER_ID, ListingAvailabilityRequest.class, mListener);
mRequestManager.unlockListeners(REQUEST_MANAGER_ID);
} else {
mRequestManager.execute(REQUEST_MANAGER_ID, new ListingAvailabilityRequest(mListener));
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (getActivity().isFinishing()){
mRequestManager.clearRequests(REQUEST_MANAGER_ID);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment