UX Optimizer – Android¶
Remote Config interface¶
Access to UX Optimizer API is possible via the below API:
Repro.getRemoteConfig()
Setting Local defaults¶
Three methods are avalible. It is recommended to call these 3 methods in your mainActivity:onCreate
before calling Repro.setup()
.
From a Map¶
HashMap<String, Object> values = new HashMap<>();
values.put("key1", "def1");
values.put("key2", "def2");
Repro.getRemoteConfig().setDefaultsFromMap(values);
From a raw Json string¶
Repro.getRemoteConfig().setDefaultsFromJsonString("{\"key1\": \"zzz1\", \"key2\": \"zzz2\"}")
From a Json file¶
Repro.getRemoteConfig().setDefaultsFromJsonFile(pathToJsonFile)
Access to Remote Config values¶
Single value¶
String value = Repro.getRemoteConfig().get("key1").asString();
Note
The return value of
Repro.getRemoteConfig().get('key1')
is always an instance ofRemoteConfigValue
and nevernull
.RemoteConfigValue
'sasString()
will return null, whiletoString()
will return an empty string if the key is not found.
All items with a certain prefix¶
Repro.getRemoteConfig().getAllValuesWithPrefix("color")
will return a Map
with all values of which keys start with color
.
Reset values¶
While in development, you may call Repro.getRemoteConfig().forceReset()
to reset to the initial state. You will have to set local defaults & fetch callbacks again, after calling forceReset()
.
Fetch & Activate¶
Everytime the app enters foreground, Remote Config values wil be retireved from the Repro server & automatically activated. Therefore, a fetch callback is not necessary. If you want to control when to apply the fetched values, you can call activateFetched()
. If you want to switch old Remote Config values for new values at a certain point in time after they have been retrieved, setting a callback is recommended.
Only one callback can be set
The callback is not gurateed to be called.
The callback timeout is set in milliseconds like other android intefaces expect.
The callback on the listener will be executed on the UI Thread.
Without a call to
Repro.setup()
, fetching is not performed and the callback will never be exceuted.A fetch callback should not be set in
onCreate
and only inonResume
of the main activity.activateFetched()
should be excecuted after the callback has been exceuted. From within the callback block is of course also possible. Like in the follwoing example.
fetch example
Repro.getRemoteConfig().fetch(3000, new RemoteConfigListener() {
@Override
public void onCompletion(FetchStatus status) {
if (status == FetchStatus.SUCCESS) {
Log.d("remote_config", "BEFORE " + Repro.getRemoteConfig().getAllValues().toString());
Repro.getRemoteConfig().activateFetched();
Log.d("remote_config", "AFTER " + Repro.getRemoteConfig().getAllValues().toString());
}
}
});