Remote Config with Firebase on Android
By: Hsiangyu Jamie
Tags: Android App Development, Software Development, Android Developers, Firebase, Android

Firebase is a powerful Google Platform which helps we build better mobile apps and grow our business. There are many different features are offered by the Firebase. In this article, I will introduce Remote Config feature.

Remote Config

The biggest challenge as a APP developers is getting your users to update their apps. Remote Config lets you change the behavior and appearance of your app without deploying new version and requiring users to download an app update. When you using remote config, you create in-app default value, then you can use Firebase console to control values for various condition. Your App should apply the behavior and appearance according to Remote Config. You can see how does Remote Config work on official document.

The benefits of Remote Config

Testing out new features is very important to the success of your app. You need to quickly adapt to your user’s feedback. Remote Config comes in handy when you want to change the look and feel of your app from Firebase cloud. For example, you want to do experiment on how well a card with image attracts users to click, compared with a card without image does.

As a result, why should I user Remote Config? The most important advantage is you can update your app without deploying you app. It’s useful, right? The other benefit is you can customize value for different condition and track the impact. In addition, Remote Config is very suitable for A/B testing.

How to using Remote Config on Android

1. Add Remote Config in your project

Add the dependency for Remote Config to you app-level build.gradle file

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

2. Setting up the parameters in Firebase Console

In Firebase console, set up the following parameter. You just need to filled in Parameter key and default value, then click ADD PARAMETER

and don’t forget to click PUBLISH CHANGES

After adding parameter, you also can add value for condition(optional). A condition is used to target a group of app users. Conditions let you to apply different parameter value based on app, market/region, user in random percentile, device language, etc.

For example, you can add value for condition. The setting of value is true, and this applies to ZA market.

3. Implement Remote Config in your app

First, you need to get a Remote Config object instance and enable developer mode, which you can use to increase the number of fetches available per hour during development.

FirebaseRemoteConfigSettings remoteConfigSettings = new FirebaseRemoteConfigSettings

.Builder()

.setDeveloperModeEnabled(BuildConfig.DEBUG)

.build();

firebaseRemoteConfig.setConfigSettings(remoteConfigSettings);

Then, set in-app default values from an XML file. This XML file is should be put in your .../res/xml directory. An app uses in-app default value, and when fetch Remote Config tasking successful, it will override your in-app default value.

mFirebaseRemoteConfig.setDefaults(R.xml.remote_config_defaults);

About Remote Config XML file, each entry has key and value. The value could be retrieved as long, double, String or boolean. Note that the key have to be same as parameter key which you set on Firebase console.

<?xml version="1.0" encoding="utf-8"?>

<defaultsMap>

<entry>

<key>showRecentSearchImage</key>

<value>false</value>

</entry>

</defaultsMap>

After finishing setting default value in app, how should you fetch remote value from Firebase server? Below is the block of code. You can notice that you can set cache expiration when you fetch Remote Config from server. The default cache expiration is 12 hours, you can set 0 if developer mode enabled, it will fetch remote config frequently, it’s very useful for debugging. In addition, when fetched values has succeed, don’t forget to call firebaseRemoteConfig.activateFetched() , it must be activated before newly fetched values are returned.

Finally, let’s go to use values. You need to retrieve the value from FirebaseRemoteConfig object using the same key name.

firebaseRemoteConfig.getBoolean("showRecentSearchImage")

Now, you can use this value for displaying image or not.

Conclusion

Remote Config is very useful for delivering the right user experience to users. You can quickly and easily update your app without deploy your app to play store. Try to use Firebase Remote Config, then MAKE AWESOME APP.