android - 除非重新启动(杀死)应用程序,否则刷新 Firebase 中的远程配置不会更新
问题描述
我开始实现远程配置,并在更新服务器上的信息后进行获取,但是当我重新启动(终止)应用程序时,远程信息已更新并且对应用程序可见。更新在(杀死/重新启动)应用程序之后立即发生。我应该在应用程序中做什么才能在不终止应用程序的情况下获取更新?用户不会杀死应用程序,但它需要来自远程配置的新信息。我使用了 2 种方法:第一种是 On Create:
FirebaseRemoteConfig.getInstance().fetchAndActivate().addOnCompleteListener(this, new OnCompleteListener<Boolean>() {
@Override
public void onComplete(@NonNull Task<Boolean> task) {
if (task.isSuccessful()) {
boolean updated = task.getResult();
if (updated) {
//do some updates on local device with the info.
}
Logs.logMsg("Fetch and activate succeeded. Config params updated: " + updated);
} else {
Logs.logMsg("task is NOT Successful. Fetch failed!");
//try later
}
}
});
第二个是在将更新推送到服务器后进行刷新(Firebase 远程配置):
FirebaseRemoteConfig.getInstance().fetch(cacheExpirationSeconds).addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Logs.logMsg("Fetch and activate succeeded. ");
//do some updates on local device with the info.
} else {
Logs.logMsg("task is NOT Successful. Fetch failed!");
//try again later.
}
}
});
解决方案
令我惊讶的是,远程配置似乎实际上并不是实时的
因此,为了让您的用户获得实时更新,您必须发送静默推送通知,并在收到这些推送后,请求更新
官方文档
https://firebase.google.com/docs/remote-config/propagate-updates-realtime#android_1
人们如何类似地使用它
https://medium.com/iguanafix-engineering/real-time-remote-config-on-ios-f6d3ca35e8dc
推荐阅读
- amazon-web-services - AWS Glue Crawler - 读取具有单列的文件
- angular - 使用 angular 8 和 font awesome 的基于文本的动态更改图标
- sql - 重写查询以提高效率
- r - 通过 select 语句传递向量
- scala - 如何强制 sbt 使用与依赖项目兼容的 scalaVersion 来解决依赖关系
- spring - 当我想连接有这个问题“错误”:“内部服务器错误”,“消息”:“没有可用的消息”,
- git - 为 Git 分叉更新 go 资产路径
- html - 动态 V-for 显示没有结果(Vue.js)
- firebase - 为什么我的 DocumentSnapshot DocumentID 在我的数据库中返回 null?
- python - 是否有 python 函数来替换文本文件中特定列表中的特定索引?