I have a simple fragment that handles logins for my application. Since I\'m dealing with login requests, I do not want to cache them. This strategy works fine until I introd
Use cache. Execute request with some cache key
spiceManager.execute(request, "your_cache_key", DurationInMillis.ALWAYS_EXPIRED, new AccessTokenResponseRequestListener());
and in listener remove response on this request from cache if it returned successfully before you switched to another activity as you do not want to cache the account information as per your requirement.
@Override
public void onRequestFailure(SpiceException e) {
....
spiceManager.removeDataFromCache(AccessTokenResponse.class);
....
}
@Override
public void onRequestSuccess(AccessTokenResponse accessToken) {
if (accessToken == null) {
return;
}
....
spiceManager.removeDataFromCache(AccessTokenResponse.class);
....
}
In onStart try to get cached response if you switched to another activity and now come back to the previous activity. This return response which arrive after you call spiceManager.shouldStop(). Otherwise return null.
spiceManager.getFromCache(AccessTokenResponse.class, "your_cache_key", DurationInMillis.ALWAYS_RETURNED, new AccessTokenResponseRequestListener());