我正在处理的应用程序,有时可以正常工作,但有时候它会给我这个错误
致命异常: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();
}
Run Code Online (Sandbox Code Playgroud)
调用方法onCreate():
loc = new MyLocation(MainActivity.this);
if (loc.checkPlayServices()) {
loc.buildGoogleApiClient();
loc.createLocationRequest();
}
Run Code Online (Sandbox Code Playgroud)
但它有时会一直给出同样的错误,不知道为什么会发生这种情况?!