I'm trying to implement calling Firebase Remote Config fetch()
method in onStart()
. I thought it would be quite easy but after few attempts it isn't.
First of all, I want to check for new config values as soon as the user opens the app and cache expiration time was exceeded. That's why I chose onStart()
method to do this.
At first I used standard approach:
//called in Activity onStart() method
public static void fetchRemoteConfigValues(Activity activity) {
long cacheExpirationInSeconds = 43200L;
firebaseRemoteConfig.fetch(cacheExpirationInSeconds)
.addOnSuccessListener(activity, new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
LOGD(TAG, "onSuccess: Fetch Succeeded");
FirebaseRemoteConfig.getInstance().activateFetched();
}
})
.addOnFailureListener(activity, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
LOGE(TAG, "onFailure: Fetch Failed", e);
}
});
}
Everything would work correct except that there is a situation when cache expiration time is exceeded and there is no Internet connection so onFailure
is called. And now my question is:
- Why is this failure request increases throttle counter?
After few fetch() calls with no Internet FirebaseRemoteConfigFetchException
turns in FirebaseRemoteConfigFetchThrottledException
. And now even if Internet is available again I can't fetch data from the server because of throttle limit on.
My temporary workaround is checking Internet availability before calling fetch():
public static void fetchRemoteConfigValues(Activity activity) {
if (NetworkHelper.isNetworkAvailable(activity))
long cacheExpirationInSeconds = 43200L;
firebaseRemoteConfig.fetch(cacheExpirationInSeconds)
(...)
}
}
But it can cause some problems when connection is established but still no Internet / no server response.
- Is there a better solution / approach to my problem?
来源:https://stackoverflow.com/questions/44091088/how-to-implement-fetch-from-firebase-remote-config-in-onstart-method