Remote Config lets your app change its behavior and appearance without updating the app. You can update settings or features remotely.
You want to change app colors or text without releasing a new version.
You want to enable or disable features for some users remotely.
You want to run A/B tests by changing values for different user groups.
You want to fix small bugs or tweak settings quickly without app store approval.
You want to personalize app content based on user location or preferences.
Syntax
Android Kotlin
val remoteConfig = Firebase.remoteConfig
val configSettings = remoteConfigSettings {
minimumFetchIntervalInSeconds = 3600
}
remoteConfig.setConfigSettingsAsync(configSettings)
remoteConfig.setDefaultsAsync(R.xml.remote_config_defaults)
remoteConfig.fetchAndActivate().addOnCompleteListener { task ->
if (task.isSuccessful) {
val welcomeMessage = remoteConfig.getString("welcome_message")
}
}
Use fetchAndActivate() to get and apply remote values.
Set default values in XML to have fallback if fetch fails.
Examples
Simple fetch and activate remote config values.
Android Kotlin
val remoteConfig = Firebase.remoteConfig
remoteConfig.fetchAndActivate()
Set default values programmatically instead of XML.
Android Kotlin
remoteConfig.setDefaultsAsync(mapOf("welcome_message" to "Hello!"))
Get a string value from remote config.
Android Kotlin
val message = remoteConfig.getString("welcome_message")
Sample App
This app shows a message from Remote Config on screen. It sets a default message, fetches remote values, and updates the text.
Android Kotlin
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.google.firebase.ktx.Firebase
import com.google.firebase.remoteconfig.ktx.remoteConfig
import com.google.firebase.remoteconfig.ktx.remoteConfigSettings
import android.widget.TextView
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val textView = TextView(this)
setContentView(textView)
val remoteConfig = Firebase.remoteConfig
val configSettings = remoteConfigSettings {
minimumFetchIntervalInSeconds = 3600
}
remoteConfig.setConfigSettingsAsync(configSettings)
remoteConfig.setDefaultsAsync(mapOf("welcome_message" to "Welcome!"))
remoteConfig.fetchAndActivate().addOnCompleteListener { task ->
if (task.isSuccessful) {
val message = remoteConfig.getString("welcome_message")
textView.text = message
} else {
textView.text = "Failed to load message"
}
}
}
}
OutputSuccess
Important Notes
Remote Config values are cached locally for the minimum fetch interval.
Always set default values to avoid empty or null results.
Test remote config changes carefully before releasing to all users.
Summary
Remote Config lets you change app behavior without app updates.
Use fetchAndActivate() to get and apply values.
Always provide default values for safety.
Practice
(1/5)
1. What is the main purpose of Firebase Remote Config in an Android app?
easy
A. To manage user authentication and login
B. To store user data locally on the device
C. To change app behavior and appearance without releasing a new app version
D. To handle app crashes and error reporting
Solution
Step 1: Understand Remote Config functionality
Remote Config allows developers to update app behavior remotely without requiring users to download a new version.
Step 2: Compare options with Remote Config purpose
Options B, C, and D relate to other Firebase services, not Remote Config.
Final Answer:
To change app behavior and appearance without releasing a new app version -> Option C
Quick Check:
Remote Config = Change app behavior remotely [OK]
Hint: Remote Config updates app without new installs [OK]
Common Mistakes:
Confusing Remote Config with local data storage
Mixing Remote Config with authentication features
Thinking Remote Config handles crash reports
2. Which Kotlin code snippet correctly fetches and activates Remote Config values asynchronously?
easy
A. remoteConfig.fetchAndActivate().addOnCompleteListener { task -> if (task.isSuccessful) { applyConfig() } }
B. remoteConfig.fetch().activate()
C. remoteConfig.activate().fetch()
D. remoteConfig.fetchAndActivate { applyConfig() }
Solution
Step 1: Identify correct method chaining for fetch and activate
The correct method is fetchAndActivate() which returns a Task to listen for completion.
Step 2: Check syntax for asynchronous handling
remoteConfig.fetchAndActivate().addOnCompleteListener { task -> if (task.isSuccessful) { applyConfig() } } uses addOnCompleteListener properly to handle success and then apply config.
Final Answer:
remoteConfig.fetchAndActivate().addOnCompleteListener { task -> if (task.isSuccessful) { applyConfig() } } -> Option A
Quick Check:
fetchAndActivate() with listener = remoteConfig.fetchAndActivate().addOnCompleteListener { task -> if (task.isSuccessful) { applyConfig() } } [OK]
Hint: Use fetchAndActivate() with addOnCompleteListener [OK]
Common Mistakes:
Calling activate() before fetch()
Using fetch() and activate() separately without chaining
Passing a lambda directly to fetchAndActivate()
3. Given this Kotlin code snippet, what will be printed if the Remote Config parameter "welcome_message" is not set remotely and default is "Hello"?
val welcome = remoteConfig.getString("welcome_message")
println(welcome)
medium
A. Hello
B. null
C. An empty string
D. welcome_message
Solution
Step 1: Understand getString behavior with default values
If the parameter is not set remotely, Remote Config returns the default value provided in app defaults.
Step 2: Recognize default value is "Hello"
The default for "welcome_message" is "Hello", so getString returns "Hello".
Final Answer:
Hello -> Option A
Quick Check:
Missing remote value returns default string [OK]
Hint: Missing remote key returns default value [OK]
Common Mistakes:
Expecting null instead of default
Assuming empty string if not set
Confusing key name with value
4. What is wrong with this Kotlin code snippet for fetching Remote Config values?