来自iOS开发人员学习Android的两部分问题,研究Android项目,该项目将发出从JSON到图像到音频和视频的流媒体下载的各种请求:
在iOS上,我广泛使用了AFNetworking项目.是否有适用于Android的等效库?
我已经阅读了OkHTTP和Square的改造,以及Volley,但还没有与他们一起开发的经验.我希望有人可以提供一些最佳使用案例的具体例子.从我所看到的,看起来OkHTTP是三者中最强大的,并且可以处理这个项目的要求(如上所述).
在我的项目中,我使用volley来下载一个JSON流,我将其解析并显示在列表视图中.我使用以下方法加载我的数据:
private void loadEventData(int year, final int month) {
// get volley request queue
requestQueue = cpcApplication.getRequestQueue(getActivity());
String url = "****************?year=" + year
+ "&month=" + month;
pd = ProgressDialog.show(getActivity(), "Loading Events", "Retrieving Data from Server");
pd.setCancelable(true);
JsonObjectRequest jr = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.i(TAG, response.toString());
// parse the incoming response
parseJson(response, month);
// notify the listview that the data set has changed
adapter.notifyDataSetChanged();
// set the listview at the top …Run Code Online (Sandbox Code Playgroud)