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.
What is Firebase Remote Config
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.
Why Firebase Remote Config
- Make modifications without having to republish
- Customize every aspect of your app
- Customize the app for different types of users.
- You can test new functionalities on a small number of people.
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.
States of 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:
Firebase Remote Config in Action
Let’s create a small app with an image view that will get the image URL from the remote config.
Create a Basic Sample app
- Create a new project and choose the template of your choice.
I chose “Empty Activity”.
- Add name and click finish
- Add an ImageView in the activity layout
Create a Firebase Project
To use any firebase tool, we need to create a firebase project for the same.
Let’s create one for our app RemoteConfigSample
- Go to https://console.firebase.google.com/ and create a new project by clicking “Add Project”
- Give any name for your project and click `Continue`
- Give any name for your project and click `Continue`
- Select your Analytics location and create the project.
Add Android App to Our Firebase Project
- Click on the Android icon to create an Android app in the firebase project
- After filing the relevant info click on the Register app
- Download and add google-services.json to your project as per the instruction provided.
- Click Next after following the instructions to connect the Firebase SDK to your project.
Add Firebase Remote Config Dependencies
Add the following line in-app module build.gradle dependencies and then sync the project.
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
Implementation for Fetching Remote Config
- Get the singleton object of Remote Config.
- Set the in-app default parameter value
- Create a method for fetching from the firebase remote server
- Create a button in the activity layout to trigger the fetch call
App in Action
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
- Don’t update or switch aspects of the UI while the user is viewing or interacting with it. You can do this only if you have a strong app or business reasons for doing so, like removing options related to a promotion that has just ended.
- Don’t send mass numbers of simultaneous fetch requests, as it may lead to the server throttling your app. Risks of this happening are low in most production scenarios.However, it can be an issue during active development.
- Do not store confidential or sensitive data in Remote Config parameters.
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