问题描述
我implmenet GoogleApi客户波纹管:
I implmenet GoogleApi client as bellow:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, 0 /* clientId */, this)
.addApi(LocationServices.API)
.addApi(Places.GEO_DATA_API)
.addConnectionCallbacks(this)
.build();
但在onConnected方法我检查mGoogleApiClient => null值。
在这种情况下,我尝试重新建立googleApiClient但我得到的错误:
But in onConnected method I check mGoogleApiClient => value null.In this case I try to re-build googleApiClient but I get error:
java.lang.IllegalStateException: Already managing a GoogleApiClient with id 0
请帮助我了解为什么mGoogleApiClient一段时间NULL althought它的连接:|。 (注,我查了所有的源$ C $ C,我从未GoogleApiClient为NULL)。
Please help me understand why mGoogleApiClient some time NULL althought it's connected :|. (Notes. I checked all source code, I never set GoogleApiClient to NULL).
谢谢!
推荐答案
我有同样的问题。我所做的,解决它删除 .enableAutoManage(这一点,0 / * *的clientId /,这一点)
,因为它只是不正确地从我假定工作。然后,覆盖您的活动这些方法:
I had the same problem. All I did to solve it is remove .enableAutoManage(this, 0 /* clientId */, this)
because it just doesn't work properly from what I assumed. Then, override these methods in your activity:
@Override
protected void onStart() {
super.onStart();
if (mGoogleApiClient != null)
mGoogleApiClient.connect();
}
@Override
protected void onStop() {
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
super.onStop();
}
从技术上讲,这就是 .enableAutoManage(这一点,0 / * *的clientId /,这一点)
是应该做的,但现在,一切正常,因为它应该。
Technically, that is what .enableAutoManage(this, 0 /* clientId */, this)
was supposed to do, except that now, everything works as it should.
这篇关于谷歌API客户端在某个时候onConnected NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!