连接暂停后什么是GoogleApiClient重新连接策略? [英] What is the GoogleApiClient Reconnect Policy after a connection gets suspended?

查看:127
本文介绍了连接暂停后什么是GoogleApiClient重新连接策略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GoogleApiClient模糊的javadoc告诉我们:

  GoogleApiClient.ConnectionCallbacks.onConnectionSuspended 

将会是:


客户端暂时处于断开状态。如果远程服务出现问题(例如崩溃或资源问题导致它被系统中止),就会发生这种情况。被调用时,所有请求都被取消,没有未完成的侦听器将被执行。 GoogleApiClient会自动尝试恢复连接。应用程序应该禁用需要该服务的UI组件,并等待对onConnected(Bundle)的调用以重新启用它们。


不幸的是它不会告诉我们它将重试恢复连接的次数。是否有超时,指数退避,重试次数?

如果它没有成功神奇地恢复连接,它会调用:

  OnConnectionFailedListener.onConnectionFailed 

以及何时?

解决方案

如果我记得正确的话,我已经推出了项目,并且代码已经改变了......

,它会尝试重新连接一次,假定由于服务崩溃导致连接被挂起(最常见的原因)。然后我会假设它最终会调用onConnectionFailed()或 onConnected(),但我不会'不依赖于此。我想你可以通过在你的应用程序连接时杀死GMS进程来验证这一点,但即使有证据表明这种情况我仍然不会依赖它,除非它被记录在案。



如果连接失败,我不会指望它重试一次以上,或者如果它连接并且服务再次崩溃,则不会再尝试一次。



如果我正在建立一些使用客户端的东西,我希望尽可能保持防御,我不会相信暂停的连接。我会再次调用 disconnect() connect()来重新建立连接。


The vague javadoc of GoogleApiClient tells us that:

GoogleApiClient.ConnectionCallbacks.onConnectionSuspended

is going to be :

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.

Unfortunately it doesn't tells us how many times it will retry to "restore" the connection. Is there any timeout, exponential backoff , number of retries ?

If it doesn't succeed magically restoring the connection does it call:

OnConnectionFailedListener.onConnectionFailed

and when ?

解决方案

I've rolled off the project, and code has changed in the meantime...

If I recall correctly, it tries to reconnect once, assuming that the connection was suspended due to a service crash (the most common cause). Then I would assume that it'd end up calling either onConnectionFailed() or onConnected(), but I wouldn't rely on that. I think you can verify this by killing the GMS process while your app is connected, but even if evidence shows that this is the case I still wouldn't rely on it unless it's documented.

I would not expect it to retry more than once if it fails to connect, or to ever stop if it connects and the service crashes again.

If I was building something that used the client and I wanted to be as defensive as possible, I wouldn't trust a suspended connection. I'd explicitly call disconnect() and connect() again to re-build the connection.

这篇关于连接暂停后什么是GoogleApiClient重新连接策略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆