Search code examples
androidfirebase-remote-config

Firebase Remote Config: called only once time


I've implemented the basic code from Firebase documentation:

mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
        FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
                .setMinimumFetchIntervalInSeconds(20)
                .build();
        mFirebaseRemoteConfig.setConfigSettingsAsync(configSettings);

        mFirebaseRemoteConfig.fetchAndActivate()
                .addOnCompleteListener(this, new OnCompleteListener<Boolean>() {
                    @Override
                    public void onComplete(@NonNull Task<Boolean> task) {
                        if (task.isSuccessful()) {
                            boolean updated = task.getResult();
                            LogUtils.LOGD("XXXXX", "firebase remote config fetch OK");
                            treatRemoteConfigValues();

                        } else {
                            LogUtils.LOGD("XXXXX", "firebase remote config fetch failed!!!!");
                        }
                    }
                });

This callback is called just one time (during first init), I don't understand why this callback is not called every 20 seconds. I tried to update value from Firebase config interface, nothing happens too.

Thank you for your help guys!


Solution

  • It looks like you're misunderstanding what setMinimumFetchIntervalInSeconds(20) actually means. It does not mean that the SDK will refresh the values automatically for you. According to the API documentation:

    Sets the minimum interval between successive fetch calls.

    Fetches less than duration seconds after the last fetch from the Firebase Remote Config server would use values returned during the last fetch.

    This means the following: when you call fetch(), the SDK will not actually fetch new values until after the specified time since the last successful fetch. The limit helps prevent your code from "spamming" Remote Config with repeated requests, whether intentionally or accidentally. Remote Config will enforce a server side rate limit also, in order to defend itself from misbehaving code.

    If you need more realtime updates for some values on a server, consider instead using Realtime Database or Firebase, which lets you establish listeners for immediate feedback when some value changes. Of course, you will not be able to use Remote Config's powerful configurations.