使用改造 return 来自 API 的信息,如何在其他 类 中使用它?
Using retrofit to return information from an API, how do I use this in other classes?
所以我(我认为)为我的应用程序设置了一种从 Web 服务中提取信息的方法。但是我不确定如何将此信息放入 variables/use 其他 class 中的信息?
我设置了一个改造 class:
public static final String URL = "baseURLhere";
public void setupRF(){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
我有另一个 class 镜像将返回的 JSON:
public class Friends {
private String name;
private double lon;
private double lat;
private List<Friends> friends;
getters and setters (omitted)...
}
最后我有:
public interface FriendsInterface {
@GET("restofURLhere.php")
Friends getFriends();
}
所以根据我的理解,如果我到目前为止所做的一切都正确,那么 getFriends() 方法应该调用来自 API 的信息 - 但是我如何将这些存储到我的特定变量中?我假设一旦它们被存储,我就可以像其他 classes/activities?
中的常规变量一样调用它们
在此先感谢大家。
所以我(我认为)为我的应用程序设置了一种从 Web 服务中提取信息的方法。但是我不确定如何将此信息放入 variables/use 其他 class 中的信息?
我设置了一个改造 class:
public static final String URL = "baseURLhere";
public void setupRF(){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
我有另一个 class 镜像将返回的 JSON:
public class Friends {
private String name;
private double lon;
private double lat;
private List<Friends> friends;
getters and setters (omitted)...
}
最后我有:
public interface FriendsInterface {
@GET("restofURLhere.php")
Friends getFriends();
}
所以根据我的理解,如果我到目前为止所做的一切都正确,那么 getFriends() 方法应该调用来自 API 的信息 - 但是我如何将这些存储到我的特定变量中?我假设一旦它们被存储,我就可以像其他 classes/activities?
中的常规变量一样调用它们在此先感谢大家。