gpt4 book ai didi

android - FirebaseRemoteConfig.fetch() 不会每次都触发 OnCompleteListener

转载 作者:IT老高 更新时间:2023-10-28 21:59:26 25 4
gpt4 key购买 nike

我正在尝试实现 Firebase 远程配置:

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")
//...
}

我的问题是 OnCompleteListener 并不总是被调用。如果我多次关闭/打开我的应用程序,setupView() 并不总是被触发。

应该始终调用 OnCompleteListener 对吗?即使我正在访问缓存?

编辑:即使我禁用开发者模式,行为也是一样的。有时会触发回调,有时不会。

最佳答案

我遇到了同样的问题并联系了 Firebase 支持。他们回复如下:

There currently is a bug that has been reported where onComplete, onSuccess, and onFailure listeners doesn't get called if fetch() is called too early. [...] Currently there is a work around where you can put the fetch() inside a postResume. You can try using this in the meantime before a solution has been released.

我相应地实现了解决方法

protected void onPostResume() {
super.onPostResume();

mFirebaseRemoteConfig.fetch(cacheExpiration)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d(TAG, "Fetch Succeeded");
// Once the config is successfully fetched it must be activated before newly fetched values are returned.
mFirebaseRemoteConfig.activateFetched();
// Do whatever should be done on success
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.d(TAG, "Fetch failed");
// Do whatever should be done on failure
}
});
}

到目前为止,他们提出的解决方法似乎已经解决了这个问题。

更新:

我刚刚收到了 Firebase 支持的通知。据他们说,最新的 Google Play 服务更新解决了这个问题。

A fix to Remote Config not calling listeners after fetching has been released in the newest Google play services update. I'll be closing this case for now. However if you are still experiencing issues, feel free to reach out and let me know.

关于android - FirebaseRemoteConfig.fetch() 不会每次都触发 OnCompleteListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37501124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com