java - 如何每 10 分钟向改造服务器发送一次发布请求?
问题描述
我真的需要帮助!我有一台服务器可以向我发送预测时间。我需要每 10 分钟向服务器发送一次请求(即使应用程序关闭)并询问当前时间。如果时间改变,我需要通知客户。停止触发器是预测时间是否是现在。
所以-我有 ClientActivity
并且我有与服务器通信的代码。
我怎样才能做到这一点?
非常感谢!
public interface APIClient {
@POST("/api/post_some_data")
Call<PostResponse> getPostRequest(@Body PostRequest body);
}
public class NetworkClient {
public static final String BASE_URL = "http://*****:8080";
public static Retrofit retrofit;
/*
This public static method will return Retrofit client
anywhere in the appplication
*/
public static Retrofit getRetrofitClient() {
//If condition to ensure we don't create multiple retrofit instances in a single application
if (retrofit == null) {
//Defining the Retrofit using Builder
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL) //This is the only mandatory call on Builder object.
.addConverterFactory(GsonConverterFactory.create()) // Convertor library used to convert response into POJO
.build();
}
return retrofit;
}
}
解决方案
推荐阅读
- c# - 从延迟加载模型创建 DbQuery
- amazon-cloudwatch - 从 Fargate 容器内运行 AWS 日志代理
- python-3.x - 如何将 datetime.datetime(YYYY,mm,dd,HH,MM,SS) 格式转换为十进制 YYYYmm.DDHH
- javascript - 用于禁用 youtube 视频的鼠标单击的 Javascript 代码
- php - 如何在 PHP 中使用 shell_exec 运行带有参数的 .sh 文件?
- php - 是否可以将 URL 传递的“PHP”变量作为 SQL 查询的比较元素传递?
- docker - 使用 ramdisk 的机器上的 Docker 不起作用
- scala - 将 RDD 解析为键值对
- typescript - WebStorm 不支持 TypeScript 的 `enum` 或 `readonly`
- javascript - 如何从 ipcRenderer.on 事件监听器中注销?