首页 > 解决方案 > 除非重新启动(杀死)应用程序,否则刷新 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.
                            }
                        }
                    });

标签: androidupdatesfirebase-remote-config

解决方案


令我惊讶的是,远程配置似乎实际上并不是实时的

因此,为了让您的用户获得实时更新,您必须发送静默推送通知,并在收到这些推送后,请求更新

StackOverflow 上其他答案的步骤

官方文档

https://firebase.google.com/docs/remote-config/propagate-updates-realtime#android_1

人们如何类似地使用它

https://medium.com/iguanafix-engineering/real-time-remote-config-on-ios-f6d3ca35e8dc


推荐阅读