android – RemoteConfig Without Internet Giving Empty String-ThrowExceptions

Exception or error:

I have this class that I use to get the remote configs from Firebase.

internal object MyConfig {

    const val KEY = "test_key"

    private var remoteConfig: FirebaseRemoteConfig = FirebaseRemoteConfig.getInstance()

    init {
        val configSettings = FirebaseRemoteConfigSettings.Builder()
            .setMinimumFetchIntervalInSeconds(3600)
            .build()
        remoteConfig.setConfigSettingsAsync(configSettings)
        remoteConfig.fetchAndActivate()
    }

    fun getKey(): String {
        return mRemoteConfig.getString(KEY)
    }
}

This works ok but if I don’t have internet when the app opens then the key will be "". When I get internet back the key is still "" when I call the getKey().

How can I make it so that if the key comes back as the "" then the value is not stored in the remoteConfig?

How to solve:

There are no settings or configurations for individual keys or values. When you get a value from Remote Config, you will get that same value every time until the next fetch possibly changes it with a new value from the server. When a fetch completes, it will contain all the current values from server, or none of them if the fetch fails, and never an incomplete subset of values.

Remote Config doesn’t automatically try to fetch new values when your app comes online. If you want it to fetch again, you will have to write code for that, which is very much possible.

Leave a Reply

Your email address will not be published. Required fields are marked *