Reputation: 55
I'm currently trying Firebase Remote Config on Android. I gave a parameter a value: 2.2 but when I run an app it prints 2.0 for no reason in Logcat.
here is my code:
initialization:
private FirebaseRemoteConfig mRemoteConfig = FirebaseRemoteConfig.getInstance();
Setting defaults:
mRemoteConfig.setDefaults(hashMap);
Fetching:
mRemoteConfig.setConfigSettings(new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(true).build());
Getting double from remote config:
double code = mRemoteConfig.getDouble("code");
What I have done wrong?
Upvotes: 4
Views: 3545
Reputation: 125
You need to:
fetch()
to fetch the values from Firebaseand
activateFetched()
to activate the values last fetched, whenever appropriate and convenient in your app.Only after both of those steps are done will you receive the most up-to-date values set in the Firebase Console when you call getDouble("code")
.
Example usage from Firebase's Quickstart app on Github
Upvotes: 1
Reputation: 2662
You need to set the time frame to tell Firebase when to fetch the parameter.
Try code below,below example is fetch update for every 60 seconds:
final FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
// set in-app defaults
Map<String, Object> remoteConfigDefaults = new HashMap();
remoteConfigDefaults.put("CURRENT_VERSION", "2.0");
//...any other defaults here
firebaseRemoteConfig.setDefaults(remoteConfigDefaults);
firebaseRemoteConfig.fetch(60) // set the value in second to fetch every minutes
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "remote config is fetched.");
}
}
});
Upvotes: 2