Skip to content

Commit 8735ce0

Browse files
committed
android Config to "sample first"
Change-Id: Ic01e5016f91d2c92336486c4df0162054d3eba08
1 parent 60a269b commit 8735ce0

File tree

2 files changed

+80
-25
lines changed

2 files changed

+80
-25
lines changed

config/README.md

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,78 @@
11
Firebase Remote Config Quickstart
22
==============================
33

4+
The Firebase Remote Config Android quickstart app demonstrates using Remote
5+
Config to define user-facing text in an Android app.
6+
47
Introduction
58
------------
69

7-
- [Read more about Firebase Remote Config](https://firebase.google.com/docs/remote-config/)
10+
This is a simple example of using Remote Config to override in-app default
11+
values by defining service-side parameter values in the Firebase console. This
12+
example demonstrates a small subset of the capilities of Firebase Remote
13+
Config. To learn more about how you can use Firebase Remote Config in your app,
14+
see
15+
[Firebase Remote Config Introduction](https://firebase.google.com/docs/remote-config/).
816

9-
Getting Started
17+
Getting started
1018
---------------
1119

12-
- [Add Firebase to your Android Project](https://firebase.google.com/docs/android/setup).
13-
- Run the sample on Android device or emulator.
20+
1. [Add Firebase to your Android Project](https://firebase.google.com/docs/android/setup).
21+
2. [Create a Remote Config project for the quickstart sample](https://firebase.google.com/docs/remote-config/android#create_a_product_name_project_for_the_quickstart_sample),
22+
defining the parameter values and parameter keys used by the sample.
23+
3. Run the sample on an Android device or emulator.
24+
4. Change one or more parameter values in the Firebase Console (the value of
25+
`welcome_message`, `welcome_message_caps`, or both).
26+
5. Tap **Fetch Remote Config** in the app to fetch new parameter values and see
27+
the resulting change in the app.
28+
29+
Best practices
30+
--------------
31+
This section provides some additional information about how the quickstart
32+
example sets in-app default parameter values and fetches values from the Remote
33+
Config service
34+
35+
### In-app default parameter values ###
36+
37+
In-app default values are set using an XML file in this example, but you can
38+
also set in-app default values inline using other `setDefault` methods of the
39+
[`FirebaseRemoteConfig` class](https://firebase.google.com/docs/reference/android/com/google/firebase/remoteconfig/FirebaseRemoteConfig#public-method-summary).
40+
Then, you can override only those values that you need to change from the
41+
Firebase console. This lets you use Remote Config for any default value that you
42+
might want to override in the future, without the need to set all of those
43+
values in the Firebase console.
44+
45+
### Fetch values from the Remote Config service ###
46+
47+
When an app calls `fetch`, cached parameter values are used unless the last
48+
successful fetch occurred 12 hours ago, or unless a value less than 43200 (the
49+
number of seconds in 12 hours) is specified for `cacheExpirationSeconds`. If a
50+
cached value is not used, updated parameter values are fetched from the Remote
51+
Config service.
52+
53+
Fetched values are cached locally, but not immediately activated. To activate
54+
fetched values so that they take effect, call the `activateFetched` method. In
55+
the quickstart sample app, you call this method from the UI by tapping
56+
**Fetch Remote Config**.
57+
58+
You can also create a Remote Config Setting to enable developer mode, but you
59+
must remove this setting before distributing your app. Fetching Remote Config
60+
data from the service is normally limited to a few requests per hour. By
61+
enabling developer mode, you can make many more requests per hour, so you can
62+
test your app with different Remote Config parameter values during development.
63+
64+
- To learn more about fetching data from remote config, see the Remote Config
65+
Frequently Asked Question (FAQ) on
66+
[fetching and activating parameter values](https://firebase.google.com/support/faq#remote-config-values).
67+
- To learn about parameters and conditions that you can use to change the
68+
behavior and appearance of your app for segments of your userbase, see
69+
[Remote Config Parameters and Conditions](https://firebase.google.com/docs/remote-config/parameters).
70+
- To learn more about the Remote Config API, see
71+
[Remote Config API Overview](https://firebase.google.com/docs/remote-config/api-overview).
1472

1573
Result
1674
-----------
17-
<img src="app/src/screen.png" height="534" width="300"/>
75+
<img src="https://github.com/firebase/quickstart-android/raw/master/config/app/src/screen.png" height="534" width="300"/>
1876

1977
Support
2078
-------

config/app/src/main/java/com/google/samples/quickstart/config/MainActivity.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,20 @@ public void onClick(View v) {
6666
mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
6767
// [END get_remote_config_instance]
6868

69-
// Create Remote Config Setting to enable developer mode.
70-
// Fetching configs from the server is normally limited to 5 requests per hour.
71-
// Enabling developer mode allows many more requests to be made per hour, so developers
72-
// can test different config values during development.
69+
// Create a Remote Config Setting to enable developer mode, which you can use to increase
70+
// the number of fetches available per hour during development. See Best Practices in the
71+
// README for more information.
7372
// [START enable_dev_mode]
7473
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
7574
.setDeveloperModeEnabled(BuildConfig.DEBUG)
7675
.build();
7776
mFirebaseRemoteConfig.setConfigSettings(configSettings);
7877
// [END enable_dev_mode]
7978

80-
// Set default Remote Config values. In general you should have in app defaults for all
81-
// values that you may configure using Remote Config later on. The idea is that you
82-
// use the in app defaults and when you need to adjust those defaults, you set an updated
83-
// value in the App Manager console. Then the next time you application fetches from the
84-
// server, the updated value will be used. You can set defaults via an xml file like done
85-
// here or you can set defaults inline by using one of the other setDefaults methods.S
79+
// Set default Remote Config parameter values. An app uses the in-app default values, and
80+
// when you need to adjust those defaults, you set an updated value for only the values you
81+
// want to change in the Firebase console. See Best Practices in the README for more
82+
// information.
8683
// [START set_default_values]
8784
mFirebaseRemoteConfig.setDefaults(R.xml.remote_config_defaults);
8885
// [END set_default_values]
@@ -91,23 +88,23 @@ public void onClick(View v) {
9188
}
9289

9390
/**
94-
* Fetch welcome message from server.
91+
* Fetch a welcome message from the Remote Config service, and then activate it.
9592
*/
9693
private void fetchWelcome() {
9794
mWelcomeTextView.setText(mFirebaseRemoteConfig.getString(LOADING_PHRASE_CONFIG_KEY));
9895

9996
long cacheExpiration = 3600; // 1 hour in seconds.
100-
// If in developer mode cacheExpiration is set to 0 so each fetch will retrieve values from
101-
// the server.
97+
// If your app is using developer mode, cacheExpiration is set to 0, so each fetch will
98+
// retrieve values from the service.
10299
if (mFirebaseRemoteConfig.getInfo().getConfigSettings().isDeveloperModeEnabled()) {
103100
cacheExpiration = 0;
104101
}
105102

106103
// [START fetch_config_with_callback]
107-
// cacheExpirationSeconds is set to cacheExpiration here, indicating that any previously
108-
// fetched and cached config would be considered expired because it would have been fetched
109-
// more than cacheExpiration seconds ago. Thus the next fetch would go to the server unless
110-
// throttling is in progress. The default expiration duration is 43200 (12 hours).
104+
// cacheExpirationSeconds is set to cacheExpiration here, indicating the next fetch request
105+
// will use fetch data from the Remote Config service, rather than cached parameter values,
106+
// if cached parameter values are more than cacheExpiration seconds old.
107+
// See Best Practices in the README for more information.
111108
mFirebaseRemoteConfig.fetch(cacheExpiration)
112109
.addOnCompleteListener(this, new OnCompleteListener<Void>() {
113110
@Override
@@ -116,7 +113,7 @@ public void onComplete(@NonNull Task<Void> task) {
116113
Toast.makeText(MainActivity.this, "Fetch Succeeded",
117114
Toast.LENGTH_SHORT).show();
118115

119-
// Once the config is successfully fetched it must be activated before newly fetched
116+
// After config data is successfully fetched, it must be activated before newly fetched
120117
// values are returned.
121118
mFirebaseRemoteConfig.activateFetched();
122119
} else {
@@ -130,8 +127,8 @@ public void onComplete(@NonNull Task<Void> task) {
130127
}
131128

132129
/**
133-
* Display welcome message in all caps if welcome_message_caps is set to true. Otherwise
134-
* display welcome message as fetched from welcome_message.
130+
* Display a welcome message in all caps if welcome_message_caps is set to true. Otherwise,
131+
* display a welcome message as fetched from welcome_message.
135132
*/
136133
// [START display_welcome_message]
137134
private void displayWelcomeMessage() {

0 commit comments

Comments
 (0)