Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have implemented the firebase remote config feature in one of my apps. When I uninstall and run it again I can see the values are coming from the server. But When I update the values on the firebase portal and re-run my app then the values are not updating. I am following this blog. Please let me know where I am doing wrong.

What I have tried:

Kotlin
import android.graphics.Color
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings
import kotlinx.android.synthetic.main.activity_main.*


class MainActivity : AppCompatActivity() {

    private var mFirebaseRemoteConfig: FirebaseRemoteConfig = FirebaseRemoteConfig.getInstance()
    private var GREETING_CONFIG_KEY = "greeting_label"
    private var COLOR_CONFIG_KEY = "color_background"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        textview_greeting.text = "text view"

        //Enable Debug mode for frequent fetches
        val configSettings = FirebaseRemoteConfigSettings.Builder()
                .setDeveloperModeEnabled(BuildConfig.DEBUG)
                .build()
        mFirebaseRemoteConfig?.setConfigSettings(configSettings)

        getRemoteConfigValues()
    }

    private fun getRemoteConfigValues() {
        //here I have set the cache expiration duration to 1 hour
        //It means app will refresh after every 1 hour to check
        // if some changes are there in remote config
        var cacheExpiration: Long = 3600

        mFirebaseRemoteConfig?.fetch(cacheExpiration)?.addOnCompleteListener(this) { task ->
            if (task.isSuccessful) {
                Toast.makeText(applicationContext, "Fetch Succeeded", Toast.LENGTH_SHORT).show()
                mFirebaseRemoteConfig?.activateFetched()
            } else {
                Toast.makeText(applicationContext, "Fetch Failed", Toast.LENGTH_SHORT).show()
            }
            //changing the textview and backgorund color
            setRemoteConfigValues()
        }
    }

    private fun setRemoteConfigValues() {
        textview_greeting.setText(mFirebaseRemoteConfig?.getString(GREETING_CONFIG_KEY))
        val remoteValueBackground = mFirebaseRemoteConfig?.getString(COLOR_CONFIG_KEY)
        if (remoteValueBackground.isNotEmpty()) {
            main_layout.setBackgroundColor(Color.parseColor(remoteValueBackground))
        }
    }
}
Posted
Updated 13-Jun-20 3:39am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900