Skip to content

Commit 866c979

Browse files
committed
Add documentation for GoogleApiHelper#getSafeAutoManageId()
Signed-off-by: Alex Saveau <[email protected]>
1 parent f1876ed commit 866c979

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

auth/README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ startActivityForResult(
217217

218218
#### Handling the sign-in response
219219

220-
#####Response codes
220+
##### Response codes
221+
221222
The authentication flow provides several response codes of which the most common are as follows:
222223
`ResultCodes.OK` if a user is signed in, `ResultCodes.CANCELLED` if the user manually canceled the sign in,
223224
`ResultCodes.NO_NETWORK` if sign in failed due to a lack of network connectivity,
@@ -344,6 +345,23 @@ AuthUI.getInstance()
344345
});
345346
```
346347

348+
### Using the `GoogleApiClient` in your own app
349+
350+
FirebaseUI Auth heavily relies on the `GoogleApiClient` and its `enableAutoManage` method to
351+
help prevent memory leaks. However, using `enableAutoManage` can be risky because the method will throw
352+
an `IllegalStateException` if another `GoogleApiClient` is being managed with the same id.
353+
To help solve this problem, FirebaseUI provides a helper method to get a safe id that is
354+
not being used: `GoogleApiHelper#getSafeAutoManageId()`
355+
356+
#### Example usage:
357+
358+
```java
359+
new GoogleApiClient.Builder(mActivity)
360+
.enableAutoManage(mActivity, GoogleApiHelper.getSafeAutoManageId(), null /* listener */)
361+
.addApi(...)
362+
.build()
363+
```
364+
347365
### Authentication flow chart
348366

349367
The authentication flow implemented on Android is more complex than on other
@@ -352,7 +370,7 @@ represented in the following diagram:
352370

353371
![FirebaseUI authentication flow on Android](flow.png)
354372

355-
### UI customization
373+
## UI customization
356374

357375
To provide customization of the visual style of the activities that implement
358376
the flow, a new theme can be declared. Standard material design color
@@ -459,4 +477,4 @@ startActivityForResult(
459477

460478
#### Twitter
461479

462-
Twitter permissions can only be configured through Twitter's developer console.
480+
Twitter permissions can only be configured through [Twitter's developer console](https://apps.twitter.com/).

auth/src/main/java/com/firebase/ui/auth/util/GoogleApiHelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ protected GoogleApiHelper(FragmentActivity activity, GoogleApiClient.Builder bui
3232
mClient = builder.build();
3333
}
3434

35+
/**
36+
* @return a safe id for {@link GoogleApiClient.Builder#enableAutoManage(FragmentActivity, int,
37+
* GoogleApiClient.OnConnectionFailedListener)}
38+
*/
3539
public static int getSafeAutoManageId() {
3640
return SAFE_ID.getAndIncrement();
3741
}

0 commit comments

Comments
 (0)