刷新Firebase中的远程配置不会更新,除非重新启动终止该应用程序

问题描述

我开始实现Remote config,并且在更新服务器上的信息后执行提取操作,但是当我重新启动(杀死)该应用程序时,该远程信息将更新并显示给该应用程序。 更新会在(终止/重启)应用后立即进行。 在不终止应用程序的情况下,我应如何在应用程序中进行操作以获取更新?用户不会杀死该应用程序,但是它需要来自远程配置的新信息。 我有2种使用的方法: 首先是在创建时:

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.
                            }
                        }
                    });

解决方法

您将不得不再次使用fetchAndActivate。需要激活新获取的值才能看到它们。没有激活的获取不会导致任何更改。

,

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

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

来自other answer on 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