【发布时间】:2015-11-24 10:36:16
【问题描述】:
我正在处理的应用程序,有时可以正常工作,但有时会出现此错误
致命异常:java.lang.RuntimeException:无法暂停活动 {com.example.dell.locationapi/com.example.dell.locationapi.MainActivity}:java.lang.IllegalStateException:GoogleApiClient 尚未连接。
有时还会出现这个错误:
java.lang.IllegalStateException: GoogleApiClient 尚未连接。
即使调用了onConnected() 函数。
我将buildGoogleApiClient() 的调用移至onCreate() 的开头,这是我的代码:
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(context)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API).build();
}
调用onCreate()中的方法:
loc = new MyLocation(MainActivity.this);
if (loc.checkPlayServices()) {
loc.buildGoogleApiClient();
loc.createLocationRequest();
}
但有时它总是会出现同样的错误,知道为什么会发生这种情况吗?!
【问题讨论】:
-
你能通过这个吗?
标签: java android google-play-services