如果与互联网的连接丢失,我需要实现一个自动注销用户的计时器,我有一个方法来检查是否有连接,但我不知道如何做计时器。任何帮助将不胜感激
public boolean hasConnection() {
boolean retorno = false;
try {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isAvailable() && cm.getActiveNetworkInfo().isConnected()) {
retorno = true;
} else {
retorno = false;
}
} catch (Exception e) {
e.printStackTrace();
}
return retorno;
}