【问题标题】:Pass GoogleApiClient to another activity将 GoogleApiClient 传递给另一个活动
【发布时间】:2017-01-29 12:28:46
【问题描述】:
我已经阅读了相关的主题,但我找不到解决方案。
我需要在另一个声明了 GoogleApiClient 的活动中注销。
在注销活动中,我使用此代码进行注销
Auth.GoogleSignInApi.signOut(myGoogleApiClient);
为了获取 myGoogleApiClient,我尝试在 LoginActivity 中初始化 mGoogleApiClient“公共静态”,还尝试使用单例获取类的实例,然后获取客户端。
但我总是收到错误:java.lang.IllegalStateException: GoogleApiClient is not connected yet.
【问题讨论】:
标签:
java
android
android-studio
google-play-services
google-signin
【解决方案1】:
你只需要添加连接功能
mGoogleApiClient.connect();
mGoogleApiClient.registerConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(@Nullable Bundle bundle) {
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
// Get sign out result
}
});
}
@Override
public void onConnectionSuspended(int i) {
}
});