which is the best way to store default values for Firebase Remote Config?

Viewed 705

the people suggest using the .xml file like:

<entry>
    <key>onboarding_enabled</key>
    <value>false</value>
</entry>

but i already have values stored in the BaseActivity like:

public boolean onboarding_enabled = false;

then in onCreate() method:

onboarding_enabled = remoteConfig.getBoolean("onboarding_enabled");

what i prefer is keep the values but in onCreate method call the remote config. is it gonna work like this? is it better way to store default values?

1 Answers

The way to set default parameter values from XML file is Google's official instruction. I would follow that.

The reason, I guess, your way to define a variable's default is not preferable is that these FirebaseRemoteConfig#getBoolean, #getDouble, #getLong or #getString, they always return values anyway. So, that is, your default value -- pre-defined at declaration -- will never be used.

For example FirebaseRemoteConfig#getBoolean states:

Evaluates the value of the parameter in the following order:

  1. The activated value, if the last successful activate() contained the key, and the value can be converted into a boolean.
  2. The default value, if the key was set with setDefaultsAsync, and the value can be converted into a boolean.
  3. DEFAULT_VALUE_FOR_BOOLEAN.

If your FireBaseRemoteConfig has not fetched config value via network yet, it uses at first the value defined in XML file, if XML is unavailable, it uses DEFAULT_VALUE_FOR_BOOLEAN (= false) for the second choice. There is no room to be used for your pre-defined value.

Related