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 Firebase to your app.
  2. Get the Remote Config singleton object.
  3. Set in-app default parameter values.
  4. Get parameter values to use in your app.
  5. Set parameter values in the Remote Config service (as needed).
  6. Fetch and activate values from the Remote Config service (as needed).

Add Firebase to your app

Install the Firebase SDK, and be sure to add the dependency for Remote Config to your app-level build.gradle file as part of this step:

compile 'com.google.firebase:firebase-config:11.2.0'

Get the Remote Config singleton object

Get the singleton Remote Config object, using the FirebaseRemoteConfig.getInstance() method, as shown in the Remote Config quickstart sample app.

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

Set in-app default parameter values

You should set in-app default parameter values in the Remote Config object, so that your app behaves predictably before it fetches values from the Remote Config service:

  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. The Remote Config quickstart sample app uses an XML file to define default parameter names and values.
  2. Add these values to the Remote Config object using setDefaults(), as shown in the Remote Config quickstart sample app.

Get parameter values to use in your app

Now you can get parameter values from the Remote Config object. If you set values in the Remote Config service, fetch them, and then activate them, those values are available to your app. Otherwise, you 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:

Set parameter values in the service (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 corresponding 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 service (as needed)

  1. To fetch parameter values from the Remote Config service, call the fetch() method. Any values that you set in the Remote Config service 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.

Next steps

For an in-depth look at the Remote Config quickstart sample app, see Firebase Remote Config Android Sample App Walkthrough.

To learn more about using Remote Config in your app, see the Remote Config Frequently Asked Questions on fetching and activating parameter values, developer mode and throtting, and fetch timing.

Send feedback about...

Need help? Visit our support page.