1
我想手動處理GoogleApiClient
上的connect()
和disconnect()
操作。我想:GoogleApiClient:以後無法手動連接並執行signOut
- 建新
GoogleApiClient
(不enableAutoManage
) - 呼叫
connect()
- 時
onConnected()
被稱爲執行呼叫disconnect()
後signOut
signOut
超過
這裏的一個例子:
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()
}
然而,當onConnected()
被稱爲signOut
調用失敗
IllegalStateException: GoogleApiClient is not connected yet
我是不是做錯了什麼或者是從庫中的錯誤?
錯誤似乎與此[SO線程](http://stackoverflow.com/questions/29343922/googleapiclient-is-throwing-googleapiclient-is-not-connected-yet-after-onconne)相同,並且是解決。 – noogui
@noogui謝謝!在'onCreate()'中移動客戶端創建聽起來比解決方案更具有解決方法,但我想我無能爲力了。正如它在這個線程中所說的那樣,沒有辦法向Google報告這個錯誤。 – wverdese