Use Firebase Remote Config on Android

You can use Firebase Remote Config to define parameters in your app and update their values in the cloud, allowing you to modify the appearance and behavior of your app without distributing an app update. This guide shows you how to use Remote Config in your app, following these steps:

  1. Add Remote Config to your app.
  2. Set in-app default parameter values.
  3. Get parameter values to use in your app.
  4. Connect your app in the Firebase console.
  5. Set parameter values on the Remote Config Server (as needed).
  6. Fetch and activate values from the Remote Config Server (as needed).

Add Remote Config to your app

  1. Install the Firebase SDK.
  2. Add the dependency for Remote Config to your app-level build.gradle file:
    compile 'com.google.firebase:firebase-config:9.6.1'
  3. Create the singleton Remote Config object, as shown in the following example:
    mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();

This object is used to store in-app default parameter values, fetch updated parameter values from the server, and control when fetched values are made available to your app. To learn more, see Remote Config API Overview.

Set in-app default parameter values

You can set in-app default parameter values in the Remote Config object, so that your app behaves as intended before it connects to the Remote Config Server, and so that default values are available if none are set on the server.

  1. Define a set of parameter names, and default parameter values using a Map object or an XML resource file stored in your app's res/xml folder.
  2. Add these values to the Remote Config object using setDefaults().

Get parameter values to use in your app

Now you can get parameter values from the Remote Config object. If you set values on the Remote Config server, fetched them, and then activated them, those values are available to your app. Otherwise, you will get the in-app parameter values configured using setDefaults(). To get these values, call the method listed below that maps to the data type expected by your app, providing the parameter key as an argument:

Connect your app to Firebase

In the Firebase console, add your app to your Firebase project.

Set parameter values on the server (as needed)

  1. In the Firebase console, open your project.
  2. Select Remote Config from the menu to view the Remote Config dashboard.
  3. Define parameters with the same names as the parameters that you defined in your app. For each parameter, you can set a default value (which will eventually override the in-app default value) and you can also set conditional values. To learn more, see Remote Config Parameters and Conditions.

Fetch and activate values from the server (as needed)

  1. To fetch parameter values from the Remote Config Server, call the fetch() method. Any values that you set on the Remote Config Server are fetched and cached in the Remote Config object.
  2. To make fetched parameter values available to your app, call the activateFetched() method.

Because these updated parameter values affect the behavior and appearance of your app, you should activate the fetched values at a time that ensures a smooth experience for your user, such as the next time that the user opens your app.

Send feedback about...

Need help? Visit our support page.