I want to manually handle the connect()
and disconnect()
operation on the GoogleApiClient
. I'm trying to:
- build a new
GoogleApiClient
(withoutenableAutoManage
) - call
connect()
- when
onConnected()
is called performsignOut
- call
disconnect()
aftersignOut
is over
Here's an example:
fun signOut(googleApiClient: GoogleApiClient, resultCallback: (Status) -> Unit) {
Auth.GoogleSignInApi.signOut(googleApiClient).setResultCallback(resultCallback)
}
fun test() {
val googleApiClient = GoogleApiClient.Builder(activity)
.addApi(Auth.GOOGLE_SIGN_IN_API, buildGoogleSignInOptions(googleAuthId))
.build()
googleApiClient.registerConnectionCallbacks(object : ConnectionCallbacks {
override fun onConnected(connectionHint: Bundle?) {
signOut { status ->
//TODO something with status
googleApiClient.disconnect()
}
}
override fun onConnectionSuspended(cause: Int) {
//nop
}
})
googleApiClient.registerConnectionFailedListener {
//TODO handle failure
}
googleApiClient.connect()
}
However when onConnected()
is called the signOut
call fails with
IllegalStateException: GoogleApiClient is not connected yet
Am I doing something wrong or is it a bug from the library?