GoogleApiClient 的模糊 javadoc 告诉我们:
GoogleApiClient.ConnectionCallbacks.onConnectionSuspended
将会是:
Called when the client is temporarily in a disconnected state. This can happen if there is a problem with the remote service (e.g. a crash or resource problem causes it to be killed by the system). When called, all requests have been canceled and no outstanding listeners will be executed. GoogleApiClient will automatically attempt to restore the connection. Applications should disable UI components that require the service, and wait for a call to onConnected(Bundle) to re-enable them.
不幸的是,它没有告诉我们它将重试多少次以“恢复”连接。是否有任何超时、指数退避、重试次数?
如果它没有成功神奇地恢复连接,它会调用:
OnConnectionFailedListener.onConnectionFailed
什么时候?
最佳答案
我已经完成了项目,同时代码也发生了变化......
如果我没记错的话,它会尝试重新连接一次,假设连接是由于服务崩溃(最常见的原因)而暂停的。然后我假设它最终会调用 onConnectionFailed()
或 onConnected()
,但我不会依赖它。我认为您可以通过在您的应用程序连接时终止 GMS 进程来验证这一点,但即使有证据表明情况确实如此,除非有记录,否则我仍然不会依赖它。
我不希望它在连接失败时重试一次以上,或者在连接成功后服务再次崩溃时停止。
如果我正在构建使用客户端的东西并且我想尽可能地防御,我不会相信暂停的连接。我会再次明确调用 disconnect()
和 connect()
以重新建立连接。
关于java - 连接暂停后的 GoogleApiClient 重新连接策略是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36196816/