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
fabClickListener
, theToast.makeText(this, "Fetch Succeeded"
is shown? – Frank van Puffelenwelcome_message
new value (in the next click after the fetch) even though the cache should still be valid – Rafael Teles