2
votes

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?

2
you need to update ur parameter at Firebase Console as well..Did u do that?? - ken
Yeah, Parameter has value 2.2 but shows 2.0 in Logcat - George Gigauri

2 Answers

1
votes

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

                        }
                    }
                });
1
votes

You need to:

  1. call fetch() to fetch the values from Firebase

and

  1. call 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