我按如下方式实现GoogleApiClient
:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, 0 /* clientId */, this)
.addApi(LocationServices.API)
.addApi(Places.GEO_DATA_API)
.addConnectionCallbacks(this)
.build();
但是在onConnected
方法中,我检查了mGoogleApiClient =>的值为空。在这种情况下,我尝试重新构建googleApiClient,但得到错误:
java.lang.IllegalStateException: Already managing a GoogleApiClient with id 0
请帮助我理解为什么mGoogleApiClient有时是空的,尽管它是连接的:|。(注:我检查了所有的源代码,我从未将GoogleApiClient设置为空)。
谢谢!
更新
我的问题现在解决后,我尝试使用最新版本的播放服务。
感谢大家的帮助。
发布于 2015-05-23 06:49:47
我也有同样的问题。为了解决这个问题,我所做的就是删除.enableAutoManage(this, 0 /* clientId */, this)
,因为它不能像我想象的那样正常工作。然后,在您的活动中覆盖这些方法:
@Override
public void onStart() {
super.onStart();
if (mGoogleApiClient != null) {
mGoogleApiClient.connect();
}
}
@Override
public void onStop() {
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
super.onStop();
}
从技术上讲,这是.enableAutoManage(this, 0 /* clientId */, this)
应该做的事情,除了现在,一切都像它应该做的那样工作。
发布于 2015-11-24 01:19:52
Documentation说:在任何给定的时间,每个id只允许一个自动管理的客户端。要重用id,必须首先在前一个客户端上调用stopAutoManage(FragmentActivity)
。
我个人所做的是在离开活动之前调用bellow方法,在活动中我使用的是Google Api客户端。
private void stopAutoManage() {
if (mGoogleApiClient != null)
mGoogleApiClient.stopAutoManage(mActivity);
}
发布于 2015-04-14 12:59:12
我认为你最好看看这篇参考资料。
reference page of "public GoogleApiClient.Builder enableAutoManage"
在此页面中显示,如果clientId已经被自动管理,则通过IllegalStateException。因此,请使用以下命令检查代码
.enableAutoManage(this, 0 /* clientId */, this)
我认为如果你的代码出现异常,它可能会返回0作为未完成。
https://stackoverflow.com/questions/29619208
复制相似问题