I started to have a look on firebase remote config, I read the documentation and created a simple test application to understand how the cache works, but the behaviour is not clear to me.
In the code below everytime I change the welcome_message
property and click the fab button the new value of the property is fetched, I was expecting to get the new value only after the cache expires.
public class MainActivity extends AppCompatActivity {
private FirebaseRemoteConfig remoteConfig;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(this::fabClickListener);
remoteConfig = FirebaseRemoteConfig.getInstance();
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
.setDeveloperModeEnabled(false)
// .setDeveloperModeEnabled(BuildConfig.DEBUG)
.build();
remoteConfig.setConfigSettings(configSettings);
remoteConfig.setDefaults(R.xml.firebase_remote_properties);
}
private void fabClickListener(View view) {
String welcomeMessage = remoteConfig.getString("welcome_message");
Snackbar.make(view, welcomeMessage, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
remoteConfig.fetch(60_000)
.addOnFailureListener(exception -> Toast.makeText(this, "Fetch Failed", Toast.LENGTH_SHORT).show())
.addOnSuccessListener(result -> {
Toast.makeText(this, "Fetch Succeeded", Toast.LENGTH_SHORT).show();
remoteConfig.activateFetched();
})
.addOnCanceledListener(() -> Toast.makeText(this, "Fetch Canceled", Toast.LENGTH_SHORT).show());
}
...
}
Checking fetch documentation I see
To identify the current app instance, the fetch request creates a Firebase Instance ID token, which periodically sends data to the Firebase backend
On every new fetch
call a new ID is created? Also how the periodical requests works? I was expecting to call fetch only once and for a request to be sent automatically when a stale property value is requested or something similar
The caching of configuration values is explained in the documentation. Because of the throttling limits, it is not possible for your released app to immediately see changes in Remote Config values. Cached values will be used until the next fetch is allowed. The default cache expiration is 12 hours.
Remote config (short for "remote configuration") is a software development technique for mobile apps where the behavior or features of an app can be changed remotely without having to publish an app update.
Firebase Remote Config is a cloud service that lets you change the behavior and appearance of your app without requiring users to download an app update. When using Remote Config, you create in-app default values that control the behavior and appearance of your app.
Getting started Run the sample on an Android device or emulator. Change one or more parameter values in the Firebase Console (the value of welcome_message , welcome_message_caps , or both). Tap Fetch Remote Config in the app to fetch new parameter values and see the resulting change in the app.
Firebaser here!
This is a known issue which affects Remote Config SDK 16.3.0. We are actively working on a fix for the next release.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With