In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this "VolleyAir interface in use" article, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "VolleyAir interface in use" article.
Brief introduction
VolleyAir is a secondary encapsulation based on the famous Google open source network framework Volley, and absorbs some packaging experience of VolleyPlus, which makes it more effective to make network requests in the complex data processing logic layer, and makes the code of the logic layer more clean and concise. Volley was chosen for encapsulation because Volley is an extremely efficient web request frame and was developed by Google's Android team. After packaging and adapting on its basis, it will be more beneficial to our application development.
Usage
1. Customize the request address and parameters in the NetworkMoudle class according to your business needs
Public TaskHandle arrangeGetNewsList (String requestTag, String cty, String category, int page, int row, String title) {HttpRequest request = new HttpRequest (API_URL + "news/getNews"); request.addParameter ("cty", cty); request.addParameter ("category", category); request.addParameter ("page", Integer.toString (page)); request.addParameter ("row", Integer.toString (row)); request.addParameter ("title", title); request.setRequestTag (requestTag) Return center.arrange (request, volleyPostString);}
two。 Customize how to parse the received network data in the DataMoudle class according to your own business needs
Public IDData parseNewsList () throws HttpProcessException {try {JSONObject json = tryExtra (JSONObject.class); IDData data = new IDData (json.optInt ("count",-1), null); JSONArray array = json.optJSONArray ("data"); ArrayList list = new ArrayList (array = = null? 0: array.length ()); data.data = list; if (null! = array) {NewsListItem item For (int I = 0; I < array.length (); + + I) {json = array.getJSONObject (I); item = new NewsListItem (); item.id = json.optString ("id"); item.title = json.optString ("title"); item.create_time = json.optString ("create_time") Item.img = json.optString ("img"); item.category_name = json.optString ("category_name"); item.city_name = json.optString ("city_name"); item.description = json.optString ("description"); list.add (item);}} extra = data Return data;} catch (Exception e) {throw badResponseException (e);}}
3. Let the View layer (Activity, Fragment, etc.) implement the network data receiver interface
Public class MainActivity extends AppCompatActivity implements Receiver
4. Request and result processing in the View layer (Activity, Fragment, etc.)
/ * multiple network requests can be concurrent. The request result can be processed in the callback interface of the view layer through the Id of each request Task * / private void beginVolley () {TaskHandle handle_0 = networkModule.arrangeGetNewsList ("arrangeGetNewsList", null, null, 1, 10, null); handle_0.setId (0); handle_0.setReceiver (this); handle_0.pullTrigger () TaskHandle handle_1 = networkModule.arrangeUploadImg ("arrangeUploadImg", "path"); handle_1.setId (1); handle_1.setReceiver (this); handle_1.pullTrigger () } / * the network request is successful. The processing result is * @ param handle * @ param result * / @ Override public void onSucess (TaskHandle handle, DataModule result) {switch (handle.id ()) {case 0: if (result.code () = = DataModule.CodeSucess) {} txt_1.setText (result.toString ()); break Case 1: if (result.code () = = DataModule.CodeSucess) {} txt_2.setText (result.toString ()); break }} / * Network request exception. Processing result: * @ param handle * @ param error * / @ Override public void onError (TaskHandle handle, Throwable error) {switch (handle.id ()) {case 0: break; case 1: break }} the above is about the content of the article "VolleyAir Interface is in use". I believe everyone has a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.