我真的需要帮助! 我有一台服务器,可以向我发送预测时间。我需要每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;
}
}