How to Use Firebase Remote Config Efficiently?

Senior Software Engineer - 26 March 2021 -
Senior Software Engineer - 26 March 2021 -
Assume it’s a holiday, such as Holi , and you want to change your apps theme to match it. The easiest approach is to upload a new build with a new theme to the Google Play Store. But it does not guarantee that all of your users will download the upgrade. It will also be inefficient to upload a new build only to modify the style. It is doable for one time, but not if you intend to do the same for all the major festivals.
Firebase Remote Config is perfect to handle these kinds of scenarios. It makes controlling all these possible without wasting time creating a new build every time and waiting for the app to be available on the Play Store.
In this blog, I will create a sample app and discuss Firebase Remote Config and how it works.
The Firebase Remote Config service is a cloud-based service. It modifies your app’s behaviour and appearance of your app without forcing all current users to download an update from the Play Store. Essentially, Remote Config helps you to maintain parameters on the cloud, and it controls the actions and appearance of your app depending on these parameters.
We build in-app default values in Remote Config that govern the app’s actions and appearance (such as text, color, and pictures, among other things). We then retrieve parameters from the Firebase Remote Config and change the default value using Firebase Remote Config.
We can divide the state of remote config under two different category
In the default state config, the default values are specified in your app. It gets copied into the active state config and returned to the client if there is no matching key in the remote config server. The app will use the same.
The most recent configuration that is downloaded from the cloud but not yet enabled. You must first activate these config parameters, after which you must copy all values into the active Config and get it ready for the app.
The below image gives the pictorial representation of how the system prioritizes parameter values in the Remote Config backend and the app:
Let’s create a small app with an image view that will get the image URL from the remote config.
I chose “Empty Activity”.
To use any firebase tool, we need to create a firebase project for the same.
Let’s create one for our app RemoteConfigSample
Add the following line in-app module build.gradle dependencies and then sync the project.
implementation ‘com.google.firebase:firebase-config’
Build a new folder called XML in the res folder. Build a resource file named config_defaults in the XML section. Set the default values for Remote Config parameters. If you need to adjust the default values in an app, you use the Firebase Console to set a modified value with the exact values you wish to change.
Add parameters to the firebase console remote config.
Go to the “Remote Config” setting under Engage in the Left pane.
Add a sample parameter
The default parameter in-app is “https://tinyurl.com/25sskvem”
When App initially ran on the device it loaded the image from the default parameter.
When the user clicks on fetch, it fetches the parameter from the firebase remote server with the value “https://tinyurl.com/2dh9dsxa” and loads the image view
MainActivity
<script src=”https://gist.github.com/dk19121991/0d3e95c48c12a2dad78ec125b61e2b4e.js“></script>
Awesome, you made it till the end.
So we have seen how we can change app configurations without the need to create a new build. There can be many use cases around this, like getting the configuration for changing the app theme, we can have a splash screen with image/gif changed based on the different events without a need to upload a new build.
We can even have a version check to notify users about the availability of a new version or even enforce them to upgrade to a new version of the old app that is fully deprecated.
Firebase Remote Config is convenient. In a future blog, we will cover a few more use cases with Firebase Remote Config.
For more details and an in-depth view, you can find the code here
References: https://firebase.google.com/products/remote-config, https://firebase.google.com/docs/remote-config/
Leave a Reply