我的工作中的应用,工作正常,但有时一些其他时候,它给了我这个错误GoogleApiClient尚未连接异常
致命异常:了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();
}
但它一直有时给予同样的错误,任何想法,为什么这发生?!
你能设法通过这个吗? – cgr