如何检查 android 中与服务器的连接是否丢失?

How to check if connection to server is lost in the android?

在我的 android 应用程序中,如何检测到 IP 为 192.168.32.232 的服务器的连接是否丢失?一旦连接丢失,我想写一个服务class,它会在后台继续检查与服务器的连接。如果连接丢失,我的应用程序应该显示一个对话框。

您可以尝试使用 BroadcastReceiver (http://developer.android.com/training/basics/network-ops/managing.html#detect-changes) 通过调用 Kristiyan Varbanov 函数定期检查您与服务器的连接