1
GoogleApiClient
でconnect()
とdisconnect()
の操作を手動で処理したいとします。私がしようとしている:GoogleApiClient:後でsignOutを手動で接続して実行できません
- ビルド新しい
GoogleApiClient
- (
enableAutoManage
なし)コールonConnected()
が呼び出されるconnect()
- はここだ
上signOut
があるsignOut
disconnect()
後に実行例: 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