[英]Using retrofit to return information from an API, how do I use this in other classes?
因此,我(我认为)为我的应用程序设置了一种从Web服务提取信息的方法。 但是我不确定如何将该信息放入变量中/如何在其他类中使用该信息?
我在一类中设置了改造:
public static final String URL = "baseURLhere";
public void setupRF(){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
我还有另一个镜像将返回的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调用信息-但是如何将这些信息存储到我的特定变量中? 我假设一旦存储了它们,就可以像在其他类/活动中的常规变量一样调用它们了?
在此先感谢大家。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.