Tou*_*rki 21 android google-api-client google-play-services
我在服务中使用GoogleApiClient来请求融合位置更新.每件事都正常工作,但有时连接被挂起并调用onConnectionSuspended.
@Override
public void onCreate() {
...
mGoogleApiClient = new GoogleApiClient.Builder(this) // this is a Context
.addApi(LocationServices.API)
.addConnectionCallbacks(this) // this is a [GoogleApiClient.ConnectionCallbacks][1]
.addOnConnectionFailedListener(this) //
.build();
mGoogleApiClient.connect();
...
}
@Override
public void onConnectionSuspended(int arg0) {
// what should i do here ? should i call mGoogleApiClient.connect() again ? ?
}
Run Code Online (Sandbox Code Playgroud)
在上面的链接(ConnectionCallback doc)中,它说:
应用程序应禁用需要该服务的UI组件,并等待对onConnected(Bundle)的调用以重新启用它们.
但是这个对onConnected的调用将如何发生呢?我应该再次拨打mGoogleApiClient.connect()吗?或者即使在连接暂停后,mGoogleApiClient仍将继续尝试连接?
Hou*_*ell 36
GoogleApiClient会自动尝试重新连接.你不需要再打电话connect().
| 归档时间: |
|
| 查看次数: |
6539 次 |
| 最近记录: |