I'm trying to implement Firebase Remote Config :
override fun onCreate(savedInstanceState: Bundle?) {
val configSettings = FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(BuildConfig.DEBUG).build()
mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance()
mFirebaseRemoteConfig.setConfigSettings(configSettings)
mFirebaseRemoteConfig.setDefaults(R.xml.remote_config_defaults)
fetchRemoteConfig()
}
private fun fetchRemoteConfig() {
var cacheExpiration = 3600L
if (mFirebaseRemoteConfig.info.configSettings.isDeveloperModeEnabled) {
cacheExpiration = 0L
}
mFirebaseRemoteConfig.fetch(cacheExpiration)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
Log.d(TAG, "Remote config fetch succeeded")
mFirebaseRemoteConfig.activateFetched()
} else {
Log.d(TAG, "Remote config fetch failed - ${task.exception?.message}")
}
setupView()
}
}
private fun setupView() {
val text = mFirebaseRemoteConfig.getString("my_text")
//...
}
My problem is that the OnCompleteListener is not always called.
If I close/open my app several times, the setupView() is not always triggered.
The OnCompleteListener should always be called right? Even if I'm hitting cache?
EDIT: Even if I disable the developper mode the behavior is the same. Sometimes the callback is triggered, sometimes not.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…