Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fire Base ABTest
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings
class MainActivity : AppCompatActivity() {
private lateinit var remoteConfig: FirebaseRemoteConfig
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
remoteConfig = FirebaseRemoteConfig.getInstance()
val configSettings = FirebaseRemoteConfigSettings.Builder()
remoteConfig.setConfigSettingsAsync(
configSettings.setMinimumFetchIntervalInSeconds(3600L)
.build())
remoteConfig.setDefaultsAsync(R.xml.remote_config_defaults)
remoteConfig.fetchAndActivate()
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
val updated = task.getResult()
print(updated)
}
displayWelcomeMessage()
}
}
private fun displayWelcomeMessage() {
val welcomeMessage = remoteConfig.getString(WELCOME_MESSAGE_KEY)
print(welcomeMessage)
myTextView.text = welcomeMessage
}
companion object {
// Remote Config keys
private const val WELCOME_MESSAGE_KEY = "my_custom_event"
}
}